php soap:ServerServer无法处理请求. —>序列不包含任何元素

我需要使用CURL发送
XML作为soap请求.我用xml创建了

 $xml = "<?xml .............." blah blah

看起来像

  <?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><extLoginData xmlns='http://www.JOI.com/schemas/ViaSub.WMS/'><ThreePLKey>4dfdf34</ThreePLKey><Login>abv</Login><Password>abc</Password><FacilityID>1ee</FacilityID><CustomerID>xfs</CustomerID></extLoginData><orders xmlns='http://www.JOI.com/schemas/ViaSub.WMS/'><Order><TransInfo><ReferenceNum>Test</ReferenceNum><PONum>12345</PONum></TransInfo><ShipTo><Name></Name><CompanyName>Peter's Test</CompanyName><Address><Address1>7301 Lennox Ave Unit E3</Address1><Address2></Address2><City>Los Angeles</City><State>CA</State><Zip>90010</Zip><Country>US</Country></Address><PhoneNumber1>858-449-8022</PhoneNumber1><EmailAddress1>lshaules@mercatismedia.com</EmailAddress1><CustomerName>Elizabeth Shaules</CustomerName></ShipTo><ShippingInstructions><Carrier>USPS</Carrier><Mode>First Class Mail</Mode><BillingCode>Prepaid</BillingCode></ShippingInstructions><OrderLineItems><OrderLineItem><SKU>947</SKU><Qualifier>XXX</Qualifier><Qty>1</Qty></OrderLineItem></OrderLineItems></Order></orders></soap:Body></soap:Envelope>

我正在使用以下代码发送CURL请求

    $url = 'http://someurl.com/Contracts.asmx';
    $curl = curl_init();

    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_TIMEOUT, 120);
    curl_setopt($curl, CURLOPT_ENCODING, 'gzip');

    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
        'SOAPAction:"http://www.example.com/ViaSub.WMS/CreateOrders"',
        'Content-Type: text/xml; charset=utf-8',
    ));

    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $orderXml);

    $result = curl_exec($curl);

但我得到了

soap:ServerServer was unable to process request. ---> Sequence contains no elements

我搜索过但没有发现任何相关的东西.你能告诉我我做错了什么以及我是怎么做的吗?

最佳答案 这看起来像架构验证错误.您没有提供定义的链接,但快速搜索显示
this documentation page.如果您需要这个,请查看WSDL:
https://secure-wms.com/webserviceexternal/contracts.asmx?WSDL

查看Order中的元素PalletCount.你看它有minOccurs =“1”,这意味着它是强制性的.但是在你复制的xml字符串中没有这样的元素.这确实是一个缺少元素的序列. (可能还有其他一些架构不一致,仔细看看).

另外,请考虑使用SoapClient PHP class

$WSDL = 'https://secure-wms.com/webserviceexternal/contracts.asmx?WSDL';

$options = [
    'trace' => true,
    'cache' => WSDL_CACHE_NONE,
    'exceptions' => true
];

$client = new SoapClient($WSDL, $options);

$payload = [
    'extLoginData' => [
        'ThreePLKey' => '4dfdf34',
        'Login' => 'abv',
        'Password' => 'abc',
        'FacilityID' => '1ee',
        'CustomerID' => 'xfs'
    ],
    'orders' => [
        'Order' => [
           // etc...
        ]
    ]
]);

$response = $client->CreateOrders($payload);

这样客户端就可以处理模式验证,标头设置(您可以设置其他标头),命名空间和xml转换数组.

点赞