2014-05-13 44 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" />