2

I'm trying to create a simple php Soap Server.

The problem is that although I set specific parameters types in the wsdl file, in my case i set integer, I can make method calls from php with another parameter type(String, Array, Assoc Array).

Theoretically , if the php parameter type is not the same with wsdl parameter type should not throw error? In my case If i call the function with an array on server I get array, I i call the same function with string on server I get string etc.

How cand I edit the code below that my method "doMyBookSearch" to accept only integers as declared on wsdl.

Client Code:

    try{
  $sClient = new SoapClient('sample.wsdl',array('trace'=>true));
    print_r($sClient->doMyBookSearch('test'));  //I call the function with a string, and not integer as WSDL
} catch(SoapFault $e){
var_dump($e);
}

Server Code:

$server = new SoapServer("sample.wsdl");

function doMyBookSearch($yourName){
  return 'Works'; //return string
}

WSDL:

    <types>
    <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:MyBookSearch">
        <xsd:element  name="bookTitle">
            <xsd:simpleType>
                <xsd:restriction base="xsd:integer">
                    <xsd:minInclusive value="0"/>
                    <xsd:maxInclusive value="120"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:element>
    </xsd:schema>   
</types>

<message name="doMyBookSearch">
    <part name="bookTitle" type="tns:bookTitle" />
</message>

<message name="doMyBookSearchResponse">
    <part name="return" type="xsd:string" />
</message>  

<portType name="MyBookSearchPort">
    <operation name="doMyBookSearch">
        <input message="tns:doMyBookSearch" />
        <output message="tns:doMyBookSearchResponse" />
    </operation>
</portType>

1 Answer 1

1

PHP does not really care about types in this case. According to my experience with SOAP and PHP, all variables are send/received as string and it does not respect restrictions of the WSDL file.

One way to live with that would be to do the check yourself in your doMyBookSearch() function, and throw an error if needed.

Sign up to request clarification or add additional context in comments.

3 Comments

So your saying that If i would write the same soap server in java and than call doMyBookSearch from a php client with different argument than the one specified in wsdl than the client should get an error? without throuwing it manually.
I think it should but I'm not 100% sure. It would be great to test that.
Use \SoarVar function to respect types

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.