0

I have implemented this php SOAP server using Laminas library, here is my wsdl.

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost/test/api/user-notification" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" name="Demo" targetNamespace="http://localhost/test/api/user-notification">
<types>
<xsd:schema targetNamespace="http://localhost/test/api/user-notification">
<xsd:element name="notifySOAPHeader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="email" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="notifySOAPHeaderResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="notifySOAPHeaderResult" type="soap-enc:Array"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="notifyNewUser">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="correlator" type="xsd:string"/>
<xsd:element name="message" type="soap-enc:Array"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="notifyNewUserResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="notifyNewUserResult" type="soap-enc:Array"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</types>
<portType name="DemoPort">
<operation name="notifySOAPHeader">
<documentation>notifySOAPHeader</documentation>
<input message="tns:notifySOAPHeaderIn"/>
<output message="tns:notifySOAPHeaderOut"/>
</operation>
<operation name="notifyNewUser">
<documentation>notifyNewUser</documentation>
<input message="tns:notifyNewUserIn"/>
<output message="tns:notifyNewUserOut"/>
</operation>
</portType>
<binding name="DemoBinding" type="tns:DemoPort">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="notifySOAPHeader">
<soap:operation soapAction="http://localhost/test/api/user-notification#notifySOAPHeader"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="notifyNewUser">
<soap:operation soapAction="http://localhost/test/api/user-notification#notifyNewUser"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="DemoService">
<port name="DemoPort" binding="tns:DemoBinding">
<soap:address location="http://localhost/test/api/user-notification"/>
</port>
</service>
<message name="notifySOAPHeaderIn">
<part name="parameters" element="tns:notifySOAPHeader"/>
</message>
<message name="notifySOAPHeaderOut">
<part name="parameters" element="tns:notifySOAPHeaderResponse"/>
</message>
<message name="notifyNewUserIn">
<part name="parameters" element="tns:notifyNewUser"/>
</message>
<message name="notifyNewUserOut">
<part name="parameters" element="tns:notifyNewUserResponse"/>
</message>
</definitions>

Then I use Postman to test with this body

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
  <soapenv:Header>
    <ns1:notifySOAPHeader xmlns:ns1='http://localhost/test/api/user-notification'>
        <ns1:name>Shaq</ns1:name>
        <ns1:email>hello@shaq.com</ns1:email>
    </ns1:notifySOAPHeader>
  </soapenv:Header>
  <soapenv:Body>
    <ns2:notifyNewUserReception xmlns:ns2='http://localhost/test/api/user-notification'>
      <ns2:correlator>123456</ns2:correlator>
            <ns2:message>
                <message>123</message>
                <time>>2022-05-07T08:03:28Z</time>
            </ns2:message>
    </ns2:notifyNewUserReception>
  </soapenv:Body>
</soapenv:Envelope>

It works fine, however when I change xmlns:ns1="http://otherdomain.com/api" or xmlns:ns2="http://otherdomain.com/api" it shows error

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body>
        <SOAP-ENV:Fault>
            <faultcode>SOAP-ENV:Server</faultcode>
            <faultstring>Procedure 'ns2:notifyNewUser' not present</faultstring>
        </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

My question is: what does ns mean, and why I have to set ns1 and ns2 to my api url? Is there any way to fix my code to allow any ns value, my client connect to my soap server with different ns value :(

Thanks for helping

ytdm
  • 909
  • 1
  • 10
  • 15

0 Answers0