SOAP-ERROR: Encoding: Violation of encoding rules?

前端 未结 11 516
夕颜
夕颜 2021-01-02 03:42

Guys, I\'m stuck, banging my head off the desk for the past few hours.

I am trying to consume a service, and I have 8 other functions that I call that are almost IDE

相关标签:
11条回答
  • 2021-01-02 03:54

    I had this issue in PhpStorm when doing unit tests. I disabled the wsdl cache and it worked:

    ini_set("soap.wsdl_cache_enabled", "0");
    
    0 讨论(0)
  • 2021-01-02 03:55

    I had the same problem and I resolved using this syntax for __soapCall:

    ...
    $params = new SoapParam($data, 'parameters');
    
    $response = $this->__soapCall('methodName', 
        array(new SoapVar($data, XSD_ANYTYPE, 'parameters'))
      );        
    ...
    

    Instead of

    __soapCall('methodName', array($params)
    
    0 讨论(0)
  • 2021-01-02 04:00

    There's also a kind of bug in PHP where a wrong type leaves no room for giving a proper SOAPfault back to the client.

    http://bugs.php.net/bug.php?id=50547

    0 讨论(0)
  • 2021-01-02 04:03

    Similar to @bezz, my issue was also caused by the WSDL being cached in a temp directory.

    I cleared out the wsdl-* files in /tmp and it worked.

    0 讨论(0)
  • 2021-01-02 04:05

    It looks like you have a type mismatch somewhere, either while assembling your request (one of the parameters is not of type string), or the server returns something other than an int (violating the WSDL response definition and thus causing the client to consider the response invalid, as it expects something else).

    • To test the first case, ensure casting all parameters to string first
    • To test the second case, create your SoapClient with the trace option set to true in order to gain access to the actual XML answer from the server via $client->__getLastResponse() afterwards (You can use this for request debugging also via __getLastRequest()).

    Some additional observations/questions:

    • According to the posted WSDL, the 'CanLoadProductRequest' has a fifth param 'esn', which you do not supply in your function call.
    • Any reason why you use $client->__soapCall("CanLoadProduct", $params) instead of $client->CanLoadProduct($username, $password, etc.)? (The first version is a lower level variation which is intended to be used for non_WSDL scenarios. The second version might give you a more detailed error/exception)
    • Can you test the SOAP Call to CanLoadProductRequest by some other means? The error could be on the server side, trying to return a result type that does not fit the WSDL definition.
    0 讨论(0)
  • 2021-01-02 04:05

    I had the same problem when trying to pass XML as a parameter to one of my webservices. Wrapping the XML data in <![CDATA[ ... ]]> got rid of the SOAP-ERROR: Encoding: Violation of encoding rules and everything worked fine.

    Other details:
    1. The parameter was defined as xsd:string as well.
    2. WSDL was document/literal.
    3. Using built in SOAP class with php 5.2.10.

    0 讨论(0)
提交回复
热议问题