2013-07-17 74 views
0

我想调用这个Web服务http://115,186. 182.11/csws/Service.asmx?op = SendSMS与下面的PHP代码,但它给了我例外脚本中的错误队友:服务器是无法处理请求。 --->对象引用未设置为对象的实例。PHP SOAPClient请求问题

非常感谢您对此的帮助。

try  {  

$client = new SoapClient("http://115.186.182.11/csws/Service.asmx?wsdl"); 

$method = 'SendSMS'; 

$params = array(
new SoapParam('xxxxx', 'Src_nbr'), 
new SoapParam('xxxxxx', 'Password'), 
new SoapParam('xxxxx', 'Dst_nbr'), 
new SoapParam('xxxxx', 'Mask'), 
new SoapParam('Message is test message', 'Message') 
); 

$result = $client->__call($method,$params); 

} 
catch(SoapFault $e){ 
echo "Error mate in Script: " . $e->getMessage(); 
} 

echo "<pre>"; 
var_dump($result); 
echo "</pre>"; 

$xmlobj = simplexml_load_string($result); 
print_r($xmlobj); 

以下是规范...

POST /csws/Service.asmx HTTP/1.1 
Host: 115.186.182.11 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 
SOAPAction: "http://tempuri.org/SendBulkSMS" 

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <SendBulkSMS xmlns="http://tempuri.org/"> 
     <Src_nbr>string</Src_nbr> 
     <Password>string</Password> 
     <Dst_nbr>xmlxml</Dst_nbr> 
     <Mask>string</Mask> 
     <Message>string</Message> 
    </SendBulkSMS> 
    </soap:Body> 
</soap:Envelope> 
HTTP/1.1 200 OK 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <SendBulkSMSResponse xmlns="http://tempuri.org/"> 
     <SendBulkSMSResult> 
     <string>string</string> 
     <string>string</string> 
     </SendBulkSMSResult> 
    </SendBulkSMSResponse> 
    </soap:Body> 
</soap:Envelope> 

回答

0

我终于跟着下面的方法,它是在生产工作的完善。

$fields = '<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <SendSMS xmlns="http://tempuri.org/"> 
     <Src_nbr>xxxx</Src_nbr> 
     <Password>123</Password> 
     <Dst_nbr>xxxxxxxxxx</Dst_nbr> 
     <Mask>xxxk</Mask> 
     <Message>Aoa, This is Test. From xxx.</Message> 
     <TransactionID>11122276</TransactionID>  
    </SendSMS> 
    </soap12:Body> 
</soap12:Envelope>'; 
echo $fields; 


$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $postUrl); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); 
curl_setopt($ch, CURLOPT_POSTFIELDS, "$fields"); 
$response = curl_exec($ch); 
curl_close ($ch); 

在生产SMS API用该代码和代码被exected每秒超过20时间和性能是好的,阱。