Search code examples
phpxmlsoapwsdl

PHP/SOAP dont create desired xml request


I am trying to use a WSDL web service with 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. Expected to find node type 'Element' with name 'Test' and namespace ''. Found node type 'Element' with name 'parameters' and 'namespace'

When I test the WSDL source with WcfTestClient software nothing goes wrong and it returns with desired results.

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. 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.

In case you need PHP code, this is the code I am using.

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);
}

Solution

  • 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. 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. With overriding __doRequest method and replacing strings, can get rid this problem but still cant see the response. Need to wrap < wsdlMethodResponse> node with < parameter> via str_replace and finally get desired response.

    As i said this may be a temporary solution. But working for me :)