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>
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With