我正在尝试使用PHP调用SOAP方法。 Web服务是使用dotnet编写的。 我已经完成了所有可能的方法来执行此调用,但是找不到合适的解决方案。
这是我得到的代码:
$xml_post_string = '<?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>
<addSupplierxml xmlns="http://tempuri.org/">
<supdatexml>xml</supdatexml>
</addSupplierxml>
</soap:Body>
</soap:Envelope>';
$soapUrl = "http://localhost:8100/WebService.asmx";
$wsdl = 'http://localhost:8100/WebService.asmx?wsdl';
$options = array(
'uri'=>$soapUrl,
'style'=>SOAP_RPC,
'use'=>SOAP_ENCODED,
'soap_version'=>SOAP_1_2,
'cache_wsdl'=>WSDL_CACHE_NONE,
'connection_timeout'=>15,
'trace'=>true,
'encoding'=>'UTF-8',
'exceptions'=>true,
);
try {
// $soap1 = new SoapClient($wsdl);
$soap = new SoapClient($wsdl, $options);
// $xml_post_string = new SoapVar($xml_post_string,XSD_ANYXML);
$params = array('supdatexml' => $xml_post_string);
$result = $soap->addSupplierxml($params);
}
catch(Exception $e) {
die('Error:'.$e->getMessage());
}
echo '<pre>';
var_dump($result);
echo '</pre>';
使用上述代码,如果Web服务将请求参数声明为字符串,则可以将参数发送到Web服务, 如果将其声明为xmlDocument,则会出现以下错误。
在xmlSystem.NullReferenceException中写入:对象引用未设置为对象的实例。 在C:\ inetpub \ wwwroot \ App_Code \ WebService.cs:line 55中的WebService.addSupplierxml(XmlDocument supdatexml)
如果我添加以下行
$xml_post_string = new SoapVar($xml_post_string,XSD_ANYXML);
然后返回我 BAD REQUEST 错误
如果有人可以为我提供上述解决方案,那将是很棒的事情。