尝试使用Soap Web服务时,为什么SoapClient :: __ getLastRequest()中的参数为空/已损坏?

时间:2016-05-24 19:12:22

标签: php xml web-services wsdl soap-client

我们正在尝试调用由https://demo2.mvrs.com/AdrConnect/AdrConnectWebService.svc?singlewsdl处的wsdl定义的函数OrderInteractive()。它需要两个参数,一个带登录信息的通信块,一个带有数据的订单块。我知道登录信息是正确的,我们正在收到服务的响应,但是它给了我们默认的"未知的错误已经发生了#34;信息。检查__getLastRequest()的结果时,我们得到:

<ns1:OrderInteractive>
    <ns1:inCommunications>
        <Communications>
            <Host>Online</Host>
            <Account>xxxxx</Account>
            <UserID>01</UserID>
            <Password>xxxxxxxxx</Password>
            <ReportTypes>
                <Type>XML2.02</Type>
            </ReportTypes>
        </Communications>
    </ns1:inCommunications>
    <ns1:inOrder/>
</ns1:OrderInteractive>

如果你看,order参数只是空的。我的问题是为什么SOAP剥离订单块,或者为什么订单块为空?我还尝试了另外两种调用函数的方法,但两者都导致我的错误日志记录:

&#34;格式化程序在尝试反序列化消息时抛出异常:反序列化操作请求消息正文时出错&#39; OrderInteractive&#39;。结束元素&#39;身体&#39;来自命名空间&#39; http://schemas.xmlsoap.org/soap/envelope/&#39;预期。找到元素&#39; InOrder&#39;来自命名空间&#39;&#39;。第2行,第185位。&#34;

我的代码如下:

    $commsBlock = "<Communications>
                <Host>Online</Host>
                <Account>xxxxx</Account>
                <UserID>01</UserID>
                <Password>xxxxxxxxx</Password>
                <ReportTypes>
                    <Type>XML2.02</Type>
                </ReportTypes>
            </Communications>";

    $orderBlock = "<Order>
                <Handling>OL</Handling>
                <Account>xxxxx</Account>
                <ProductID>DL</ProductID>
                <State>
                    <Abbrev>" . $order['state'] . "</Abbrev>
                    <Full></Full>
                </State>
                <Subtype>3Y</Subtype>
                <Purpose>AA</Purpose>
                <License>" . $order['dln'] . "</License>
                <FirstName>" . $order['firstname'] . "</FirstName>
                <MiddleName>" . $order['middlename'] . "</MiddleName>
                <LastName>" . $order['lastname'] . "</LastName>
                <DOB>
                    <Year>" . date('Y', $order['dob']) . "</Year>
                    <Month>" . date('m', $order['dob']) . "</Month>
                    <Day>" . date( 'd', $order['dob']) . "</Day>
                </DOB>
                <Misc>TEST ORDER INTERACTIVE</Misc>
            </Order>";

    $soap_url = 'https://demo2.mvrs.com/AdrConnect/AdrConnectWebService.svc?singlewsdl'; // test system url
    $soap_params = array(
        'trace' => true,
        'exceptions' => true,
        'cache_wsdl' => false
    );
    $_client = new SoapClient($soap_url, $soap_params);
    $params = array("inCommunications" => $commsBlock, "inOrder" => $orderBlock);

    // TRY TO SEND
    try {
        $_client->OrderInteractive($params); // works, but sends broken order node
        //$_client->__soapCall('OrderInteractive', $params); // breaks, goes to catch
        //$_client->OrderInteractive(new SoapParam($commsBlock, 'InCommunications'), new SoapParam($orderBlock, 'InOrder')); // breaks, goes to catch
    } catch(SoapFault $e) {
        capDebug(__FILE__, __LINE__, "Error: SoapFault:\n"  . $e->getMessage(), '/tmp/SOAP_errors.log');
    }

1 个答案:

答案 0 :(得分:0)

class inOrder {
function inOrder($xml) {
        $this->OrderXml = $xml;
    }
}

$xml_order = '<Order>
<Handling>OL</Handling>
<ProductID>DL</ProductID>
.
.
.
<Misc>TEST ORDER INTERACTIVE</Misc></Order>';

// create our order object that is needed
$order = new inOrder($xml_order);

// create our OrderInteractive parameters
$parameters = array(
    "inCommunications" => $xml_communication,
    "inOrder"          => $order
);
try {
    $xml = $_client->OrderInteractive($parameters);
} catch (Exception $e) {
    print $e->getMessage() . "\n"; exit();
}

上面的代码有效。 WSDL期望字符串和对象为params。为订单创建了一个类,并为通信块使用了一个字符串,我们正在接收数据。