Catalin
Catalin

Reputation: 762

Php Soap function arguments

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>

Upvotes: 2

Views: 2202

Answers (1)

Julien Mahin
Julien Mahin

Reputation: 36

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.

Upvotes: 1

Related Questions