Php Soap函数参数


Php Soap function arguments

我想创建一个简单的php Soap服务器。

问题是,虽然我在wsdl文件中设置了特定的参数类型,在我的情况下,我设置了整数,我可以用另一种参数类型(字符串,数组,Assoc数组)从php进行方法调用。

理论上,如果php参数类型与wsdl参数类型不相同,不应该抛出错误?在我的情况下,如果我用服务器上的数组调用函数,我得到数组,我用服务器上的字符串调用相同的函数,我得到字符串等。

我如何编辑下面的代码,使我的方法"doMyBookSearch"只接受wsdl上声明的整数。

客户机代码:

    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 = 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>

在这种情况下PHP并不真正关心类型。根据我使用SOAP和PHP的经验,所有变量都是作为字符串发送/接收的,它不尊重WSDL文件的限制。

解决这个问题的一种方法是在doMyBookSearch()函数中自己执行检查,并在需要时抛出错误。