Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP SoapServer: How to disable 'Response' appending

I am creating a SOAP server (in Symfony using ckWebservicePlugin) which needs to comply with the following structure of request and response (I was given this as an already agreed specification).

Request:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.example.net/schemas/USSD">
  <SOAP-ENV:Header/>
  <SOAP-ENV:Body>
    <USSDMessageRequest>
      <id>43</id>
      <msid>1234567890</msid>
      <data>1*2</data>
    </USSDMessageRequest>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>  

Reponse:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Header/>
  <SOAP-ENV:Body>
    <USSDMessageResponse>
       <id>43</id>
       <msid>1234567890</msid>
       <data>
          RESPONSE DATA
       </data>
    </USSDMessageResponse>
</SOAP-ENV:Body>

The trouble I'm having is with SoapServer always produces the response as name of the requested method + 'Response' appended.

So the response XML that is being sent out looks like this:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://bw.petr.appsdev/bw/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <SOAP-ENV:Body>
      <ns1:USSDMessageRequestResponse>
         <result>
            <id>2</id>
            <msid>1234565789</msid>
            <data>RESPONSE DATA</data>
         </result>
      </ns1:USSDMessageRequestResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I would like the output to be <ns1:USSDMessageResponse> rather than <ns1:USSDMessageRequestResponse>

The WSDL I'm using looks like this:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="webservices" targetNamespace="http://bw.petr.appsdev/bw/" xmlns:tns="http://bw.petr.appsdev/bw/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
  <wsdl:types xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://bw.petr.appsdev/bw/">
      <xsd:complexType name="userCredentials">
        <xsd:sequence>
          <xsd:element name="msisdn" type="xsd:string"/>
          <xsd:element name="status" type="xsd:string"/>
        </xsd:sequence>
      </xsd:complexType>
      <xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="userCredentialsElement" type="tns:userCredentials"/>
      <xsd:complexType name="USSDResponse">
        <xsd:sequence>
          <xsd:element name="id" type="xsd:string"/>
          <xsd:element name="msid" type="xsd:string"/>
          <xsd:element name="data" type="xsd:string"/>
        </xsd:sequence>
      </xsd:complexType>
      <xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="USSDResponseElement" type="tns:USSDResponse"/>
    </xsd:schema>
  </wsdl:types>
  <wsdl:portType name="webservicesPortType">
    <wsdl:operation name="USSDMessageRequest" parameterOrder="userCredentials id msid data">
      <wsdl:input message="tns:USSDMessageRequestRequest"/>
      <wsdl:output message="tns:USSDMessageResponse" name="USSDMessageResponse"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="webservicesBinding" type="tns:webservicesPortType">
    <soap:binding xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="USSDMessageRequest">
      <soap:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="http://bw.petr.appsdev/bw/USSDMessageRequest" style="rpc"/>
      <wsdl:input xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
        <soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" parts="id msid data" use="literal" namespace="http://bw.petr.appsdev/bw/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        <soap:header xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" message="tns:USSDMessageRequestRequest" part="userCredentials" use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </wsdl:input>
      <wsdl:output xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
        <soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" parts="result" use="literal" namespace="http://bw.petr.appsdev/bw/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        <soap:header xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" message="tns:USSDMessageResponse" part="userCredentials" use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:message name="USSDMessageRequestRequest">
    <wsdl:part name="userCredentials" element="tns:userCredentialsElement"/>
    <wsdl:part name="id" type="xsd:string"/>
    <wsdl:part name="msid" type="xsd:string"/>
    <wsdl:part name="data" type="xsd:string"/>
  </wsdl:message>
  <wsdl:message name="USSDMessageResponse">
    <wsdl:part name="userCredentials" element="tns:userCredentialsElement"/>
    <wsdl:part name="result" type="tns:USSDResponse"/>
  </wsdl:message>
  <wsdl:service xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="webservicesService">
    <wsdl:port xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="webservicesPort" binding="tns:webservicesBinding">
      <soap:address xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" location="http://bw.petr.appsdev/bw/webservices.php"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

Have checked SoapServer documentation, browsed through Pro Xml And Web Services by R. Richards and just can't figure out how to tell SoapServer what the response name should be.

Thank you.

like image 697
poisson Avatar asked Apr 29 '26 10:04

poisson


1 Answers

Do you create SoapServer in WSDL mode? I mean you have construct SoapServer like this:

new SoapServer('path/to/wsdl', $options); 

the first parameter must not be null. Then the SoapServer should create response according to the WSDL. If you have troubles anyway, try it with the newest release of PHP.

like image 192
xmedeko Avatar answered May 02 '26 16:05

xmedeko