2014-05-13 30 views
0

我已经SOAP客户端和SOAP服务器用PHP写的:SOAP WSDL工作只需一人操作

Server.php

// Initializing code is omitted 

$server = new SoapServer('http://wsdl.localhost:8888/calculator_service.wsdl'); 
$server->setClass('CalculatorGateway'); 
$server->handle(); 

Client.php

// Initializing code is omitted 

$request = new Request(); 
$request->data = new DataObject(); 
$request->data->sourceValue = 10; 
$request->data->modifyBy = 5; 

$client = new SoapClient(
    'http://wsdl.localhost:8888/calculator_service.wsdl', 
    ['soap_version' => SOAP_1_2, 'classmap' => [ 
     'Response' => 'Response' 
    ]] 
); 

// $argv[1] must be one of "add" or "sub" 
$response = $client->$argv[1]($request); 
echo 'Result: ' . $response->result; 

WSDL

<definitions ...> 
<types> 
    <xs:schema elementFormDefault="qualified" 
       xmlns:tns="http://schemas.xmlsoap.org/wsdl/" 
       xmlns:xs="http://www.w3.org/2001/XMLSchema" 
       targetNamespace="http://wsdl.localhost:8888/"> 

     <xs:complexType name="DataObject"> 
      <xs:sequence> 
       <xs:element name="sourceValue" type="xs:double" minOccurs="1" maxOccurs="1"/> 
       <xs:element name="modifyBy" type="xs:double" minOccurs="1" maxOccurs="1" /> 
      </xs:sequence> 
     </xs:complexType> 

     <xs:element name="Request"> 
      <xs:complexType> 
       <xs:sequence> 
        <xs:element name="data" type="DataObject" /> 
       </xs:sequence> 
      </xs:complexType> 
     </xs:element> 

     <xs:element name="Response"> 
      <xs:complexType> 
       <xs:sequence> 
        <xs:element name="result" type="xs:double" /> 
       </xs:sequence> 
      </xs:complexType> 
     </xs:element> 
    </xs:schema> 
</types> 

<message name="addRequest"> 
    <part name="Request" element="tns:Request" /> 
</message> 
<message name="addResponse"> 
    <part name="Response" element="tns:Response" /> 
</message> 

<message name="subRequest"> 
    <part name="Request" element="tns:Request" /> 
</message> 
<message name="subResponse"> 
    <part name="Response" element="tns:Response" /> 
</message> 

<portType name="CalculatorServicePortType"> 
    <operation name="add"> 
     <input message="tns:addRequest" /> 
     <output message="tns:addResponse" /> 
    </operation> 
    <operation name="sub"> 
     <input message="tns:subRequest" /> 
     <output message="tns:subResponse" /> 
    </operation> 
</portType> 

<binding name="CalculatorServiceBinding" type="tns:CalculatorServicePortType"> 
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
    <operation name="add"> 
     <soap:operation soapAction="" /> 
     <input> 
      <soap:body use="literal" /> 
     </input> 
     <output> 
      <soap:body use="literal" /> 
     </output> 
    </operation> 
    <operation name="sub"> 
     <soap:operation soapAction="" /> 
     <input> 
      <soap:body use="literal" /> 
     </input> 
     <output> 
      <soap:body use="literal" /> 
     </output> 
    </operation> 
</binding> 

<service name="CalculatorService"> 
    <port name="CalculatorServicePort" binding="tns:CalculatorServiceBinding"> 
     <soap:address location="http://wsdl.localhost:8888/CalculatorService.php" /> 
    </port> 
</service> 
</definitions> 

我的问题:无论operatiom我请求,总是第一位的,这在结合部分声明,将被执行。例如。在这种情况下,即使我要求“sub”,也会执行“add”操作。作为experement,我喜欢这种改变顺序:

<binding name="CalculatorServiceBinding" type="tns:CalculatorServicePortType"> 
    <operation name="sub"> 
    <!-- sub operation used to be on the second place --> 
    </operation> 

    <operation name="add"> 
    <!-- add operation used to be on the first place --> 
    </operation> 
</binding> 

和现在的“分”的操作执行所有的时间。

什么问题?我的绑定部分错了吗?

回答

0

解决方案非常简单。 风格属性必须存在于soap:binding元素中。像这样:

<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />