3

I am trying to use Yii to provide a web service. The auto-generated wsdl is below. I can successfully consume the web service from the command line, but through a web browser, I get

SOAP-ERROR: Encoding: Violation of encoding rules

I am new to SOAP, so I am not sure how to debug the problem. Here is the PHP code I am using to consume the web service:

<?php
    $client=new SoapClient('{url omitted for security}',
        array('trace'=>1,'exceptions'=>1));
    try {
        $result = $client->getPerson(90043412);
        var_dump($result);
    } catch (SoapFault $fault) {
        echo $fault->getMessage() . '<br />';
        echo 'REQUEST <br />';
        echo '<pre>';
        echo $client->__getLastRequestHeaders();
        echo $client->__getLastRequest();
        echo '</pre>';
        echo 'RESPONSE <br />';
        echo '<pre>';
        echo $client->__getLastResponseHeaders();
        echo $client->__getLastResponse();
        echo '</pre>';
        echo 'TRACE <br />';
        echo '<pre>';
        var_dump($fault->getTrace());
        echo '</pre>';
    }
?>

Here is the WSDL:

<?xml version="1.0" encoding="UTF-8"?> 
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:PersonControllerwsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" name="PersonController" targetNamespace="urn:PersonControllerwsdl">
    <wsdl:types>
        <xsd:schema targetNamespace="urn:PersonControllerwsdl">
            <xsd:complexType name="Person">
                <xsd:all>
                    <xsd:element name="PIDM" type="xsd:integer"/>
                    <xsd:element name="FirstName" type="xsd:string"/>
                    <xsd:element name="MiddleName" type="xsd:string"/>
                    <xsd:element name="LastName" type="xsd:string"/>
                    <xsd:element name="PrefFirstName" type="xsd:string"/>
                    <xsd:element name="CPOBox" type="xsd:string"/>
                    <xsd:element name="Classification" type="xsd:string"/>
                    <xsd:element name="Email" type="xsd:string"/>
                    <xsd:element name="PhotoFile" type="xsd:string"/>
                </xsd:all>
            </xsd:complexType>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="getPersonRequest">
        <wsdl:part name="PIDM" type="xsd:int"/>
    </wsdl:message>
    <wsdl:message name="getPersonResponse">
        <wsdl:part name="return" type="tns:Person"/>
    </wsdl:message>
    <wsdl:portType name="PersonControllerPortType">
        <wsdl:operation name="getPerson">
            <wsdl:documentation></wsdl:documentation>
            <wsdl:input message="tns:getPersonRequest"/>
            <wsdl:output message="tns:getPersonResponse"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="PersonControllerBinding" type="tns:PersonControllerPortType">
        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="getPerson">
            <soap:operation soapAction="urn:PersonControllerwsdl#getPerson" style="rpc"/>
            <wsdl:input>
                <soap:body use="encoded" namespace="urn:PersonControllerwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="encoded" namespace="urn:PersonControllerwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="PersonControllerService">
        <wsdl:port name="PersonControllerPort" binding="tns:PersonControllerBinding">
            <soap:address location="https://localhost/whoswho/person/service?ws=1"/>
        </wsdl:port>
    </wsdl:service>
</definitions> 
nhavens
  • 252
  • 1
  • 3
  • 11
  • I am serving the web service from the same box I am using to consume the web service. If I host the php script above on another box, it successfully consumes the web service. Am I running into a browser issue? – nhavens Apr 12 '11 at 17:14
  • Every other combination of hosting and consuming the web service works. Perhaps the problem is specific to hosting a web service and consuming consuming it through a web browser on the same box using XAMPP for linux v1.7.3a and 1.8. I know it sounds bizarre, but I can't get the consume script to break any other way. – nhavens Apr 13 '11 at 01:06

4 Answers4

4

It is possible that the SOAP request is incorrectly formatted. I've been using SoapUI and by default all the parameters are set to '?' initially, if you make this request PHP will fail and respond with the error message you have reported. You cannot catch this, because no exception is thrown, this is because it is a fatal error.

You can set your own error handler for this situation using the set_error_handler() function http://php.net/manual/en/function.set-error-handler.php

Easen
  • 296
  • 1
  • 5
2

I was working to update my PHP version to 5.6.26 and this error pop-up on my web services calls. After a while, I found the issue could be fixed commenting in the PHP.ini file this line:

;always_populate_raw_post_data = -1

Reviewing the documentation, this option is deprecated in this version.

I hope this comment save time to someone.

pasachova
  • 56
  • 5
1

If I host the consume script on a different server than the one hosting the web service, it functions properly. Since web services are designed for machine-machine communication more than a machine talking to itself, this seems like an adequate solution.

nhavens
  • 252
  • 1
  • 3
  • 11
1

I know this is an old thread, but if you come across it as I did trying to figure out this problem, you might try setting the soap:address to http://127.0.0.1 instead of http://localhost. I've run into a few other forums where this helped.

CrimsonKissaki
  • 181
  • 1
  • 4