简体   繁体   English

PHP / SOAP不创建所需的xml请求

[英]PHP/SOAP dont create desired xml request

I am trying to use a WSDL web service with php/soap. 我正在尝试将WSDL Web服务与php / soap一起使用。 And it always gives a deserializing error which is exactly: 而且它总是会产生反序列化错误,该错误恰好是:

Error in deserializing body of request message for operation 'Test'. 将“测试”操作的请求消息主体反序列化时出错。 OperationFormatter encountered an invalid Message body. OperationFormatter遇到无效的消息正文。 Expected to find node type 'Element' with name 'Test' and namespace ''. 预期找到名称为“ Test”且名称空间为“''的节点类型“元素”。 Found node type 'Element' with name 'parameters' and 'namespace' 找到名称为“ parameters”和“ namespace”的节点类型“ Element”

When I test the WSDL source with WcfTestClient software nothing goes wrong and it returns with desired results. 当我使用WcfTestClient软件测试WSDL源时,没有任何问题,并且返回了预期的结果。

When I compare the request XML which created by SOAP and XML which created by WcfTestClient software, I see that difference may be the problem. 当我比较由SOAP创建的请求XML和由WcfTestClient软件创建的XML时,我看到差异可能是问题所在。 It seem like something wrong with namespace and prefixes, but I don't know how to solve it, or maybe it is something else causes the problem. 命名空间和前缀似乎有问题,但是我不知道如何解决它,或者可能是其他原因导致了问题。

The request XMLs is this: http://pastebin.com/eysnG89F . 请求XML是这样的: http ://pastebin.com/eysnG89F。

In case you need PHP code, this is the code I am using . 如果您需要PHP代码, 这就是我正在使用的代码

try{
        $soap_options = array(
            'soap_version' => SOAP_1_1,
            'cache_wsdl'   => WSDL_CACHE_NONE,
            'trace' => TRUE
        );
        $soap = new SoapClient(
            'http://url.to/web/service.svc?wsdl', $soap_options
        );
        $a = $soap->Test(
           array("login" => 
               array(
                   "FirmaId"      => 15, 
                   "KullaniciAdi" => "Asdf", 
                   "Parola"       => "Xyxy",
               )
           )
         );
        var_dump($a);
} catch (Exception $e) {
        var_dump($e);
}

I cant find the exact cause and solution but this seems like working. 我找不到确切的原因和解决方案,但这似乎可以正常工作。

First, when you give object instead of array for the wsdl method, you can get rid of item, value nodes. 首先,当为wsdl方法提供对象而不是数组时,可以摆脱项,值节点。 Node will be created by object name 将通过对象名称创建节点

$a = $soap->Test(
       (object)array("login" => 
           (object)array(
               "FirmaId"      => 15, 
               "KullaniciAdi" => "Asdf", 
               "Parola"       => "Xyxy",
           )
       )
     );

After that i realized an < parameters> node instead of < WsdlMethod> node created in request xml. 之后,我实现了一个<parameters>节点,而不是在请求xml中创建的<WsdlMethod>节点。 With overriding __doRequest method and replacing strings, can get rid this problem but still cant see the response. 通过重写__doRequest方法并替换字符串,可以摆脱此问题,但仍然看不到响应。 Need to wrap < wsdlMethodResponse> node with < parameter> via str_replace and finally get desired response. 需要通过str_replace用<parameter>包装<wsdlMethodResponse>节点,最后获得所需的响应。

As i said this may be a temporary solution. 正如我所说,这可能是一个临时解决方案。 But working for me :) 但是为我工作:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM