我正在尝试将SOAP服务集成到我们的应用程序中。对于UpdateCart
方法,他们的文档声明它需要四个属性。但是,在他们的WSDL中,可以在https://mews.mouser.com/cartservice.asmx?WSDL找到它,它表明它只需要一个属性。通常我会通过SoapClient调用该方法,如下所示:
$soapClient->UpdateCart(array('xmlCartMessage' => $value));
根据他们的文档,我应该这样称呼它:
$soapClient->UpdateCart(array(
'CartGUID' => $value1,
'Requestor' => $value2,
'MouserPartNumber' => $value3,
'Quantity' => $value4
));
然而,它不起作用。它给了我以下错误:
"faultstring":"Server was unable to process request. ---> String reference not set to an instance of a String.\nParameter name: s","faultcode":"soap:Server","detail":""
他们的文档指出UpdateCart
的请求应如下所示:
<?xml version="1.0" encoding="utf-8"?>
<CartMessage CartGUID="" Requestor=“ADI” xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CartItem MouserPartNumber="595-430F157IPM" Quantity="37" TransactionID="1" CountryCode=""/>
</CartMessage>
我注意到参数被编码为属性而不是带有值的标签。我应该如何使用SoapClient
来做?
答案 0 :(得分:0)
您可以尝试使用$ soapClient-&gt; __ doRequest()来提交请求。例如,假设$ soapClient已初始化并且其示例请求有效,请尝试类似:
$request = '<?xml version="1.0" encoding="utf-8"?>
<CartMessage CartGUID="" Requestor=“ADI” xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CartItem MouserPartNumber="595-430F157IPM" Quantity="37" TransactionID="1" CountryCode=""/>
</CartMessage>
';
$location = "https://mews.mouser.com/cartservice.asmx?WSDL";
$action = "http://tempuri.org/UpdateCart";
$result = $soapClient->__doRequest($request, $location, $action, 1);
$ location和$ action需要根据他们的WSDL设置。
答案 1 :(得分:0)
如果您要创建如下的SOAP调用:
<Element Name="John" Group="USER">DATA</Attribute>
您应该尝试这样的事情:
array('Element ' => array('_' => 'DATA', 'Name'=>'John', 'Group'=>'USER'));
所以在您的情况下,我认为应该是:
$CartItem = array('CartItem' => array('_' => '', 'CartGUID'=>$value1, 'Requestor'=>$value2));
$CartMessage = array('CartItem' => array('_' => $CartItem, 'MouserPartNumber'=>$value3, 'Quantity'=>$value4));
$soapClient->UpdateCart($CartMessage);