Skip to content

Instantly share code, notes, and snippets.

@aminin
Created December 30, 2011 11:59
Show Gist options
  • Save aminin/1539513 to your computer and use it in GitHub Desktop.
Save aminin/1539513 to your computer and use it in GitHub Desktop.
PHP SoapServer ignores invalid enum value
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="test-service-namespace">
<SOAP-ENV:Body>
<ns1:TestOperation>
<ns1:firstArgument>
<!-- Wrong enum -->
<ns1:timeGroup>FooBar</ns1:timeGroup>
<!-- Good enum -->
<ns1:customerType>CHILD</ns1:customerType>
</ns1:firstArgument>
</ns1:TestOperation>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
<?xml version='1.0' encoding='UTF-8'?>
<wsdl:definitions
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
targetNamespace="test-service-namespace"
name="TestService">
<wsdl:types>
<xs:schema targetNamespace="test-service-namespace" elementFormDefault="qualified">
<xs:simpleType name="TimeGroupEnum">
<xs:restriction base="xs:string">
<xs:enumeration value="NOGROUP"/>
<xs:enumeration value="DAY"/>
<xs:enumeration value="WEEK"/>
<xs:enumeration value="MONTH"/>
<xs:enumeration value="QUARTER"/>
<xs:enumeration value="YEAR"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="CustomerTypeEnum">
<xs:restriction base="xs:string">
<xs:enumeration value="CHILD"/>
<xs:enumeration value="ADULT"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="TestStructure">
<xs:sequence>
<xs:element name="timeGroup" type="tns:TimeGroupEnum"/>
<xs:element name="customerType" type="tns:CustomerTypeEnum"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="TestOperation">
<xs:sequence>
<xs:element name="firstArgument" type="tns:TestStructure"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="TestOperationResponse">
<xs:sequence>
<xs:element name="TestOperationResult" type="xs:string" minOccurs="0" nillable="true"/>
</xs:sequence>
</xs:complexType>
<xs:element name="TestStructure" type="tns:TestStructure"/>
<xs:element name="TestOperation" type="tns:TestOperation"/>
<xs:element name="TestOperationResponse" type="tns:TestOperationResponse"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="TestOperation">
<wsdl:part name="TestOperation" element="tns:TestOperation"/>
</wsdl:message>
<wsdl:message name="TestOperationResponse">
<wsdl:part name="TestOperationResponse" element="tns:TestOperationResponse"/>
</wsdl:message>
<wsdl:portType name="TestService">
<wsdl:operation name="TestOperation" parameterOrder="TestOperation">
<wsdl:input name="TestOperation" message="tns:TestOperation"/>
<wsdl:output name="TestOperationResponse" message="tns:TestOperationResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TestService" type="tns:TestService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="TestOperation">
<soap:operation soapAction="TestOperation" style="document"/>
<wsdl:input name="TestOperation">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="TestOperationResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TestService">
<wsdl:port name="TestService" binding="tns:TestService">
<soap:address location="http://localhost/test/service"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
<?php
// Проверка упадёт ли SOAP сервер от неправильного енума
// reportType из request.xml не соответствует определению service.wsdl.xml
function TestOperation($params)
{
print_r($params);
die();
return array('TestOperationResult' => 42);
return 42;
}
$soapServer = new SoapServer('service.wsdl.xml');
$soapServer->addFunction('TestOperation');
$request = file_get_contents('request.xml');
print_r($soapServer->handle($request));
die("\n\n");
@aminin
Copy link
Author

aminin commented Jul 19, 2012

Thanks for a detailed list of php soap server's limitations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment