2013-07-08 70 views
2

我正在嘗試使用Zend Soap Client連接.net WSDL服務。我使用下面的代碼;Zend Soap客戶端標記名稱

$client = new Zend_Soap_Client("http://ws.test.com/test/services/service.asmx", array(

     'uri' => 'http://tempuri.org', 
     'soap_version' => SOAP_1_1, 
     'wsdl' => 'http://ws.test.com/test/services/service.asmx?wsdl' 
)); 

$client->DoInventoryItemImport(array(
    'DepositorID_' => '123', 
    'UserName_'  => 'ABC', 
    'Password_'  => '123123', 
    'SecurityKey_' => '', 
    'ContinueOnError_' => true, 
    'Items_' => array(
     'InventoryItem' => array(
      'Code'    => 'testcode', 
      'Description'  => 'test description', 
      'Abccode'   => 'test', 
      'Weight'   => 10.10, 
      'ItemMainCategory' => 'testCategory', 
      'Depositor'   => 'ABC', 
      'DepositorCode'  => '123' 
     ) 
    ) 

)); 

此代碼發送SOAP信封正是這樣一個;

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <SOAP-ENV:Body> 
     <ns1:DoInventoryItemImport> 
      <ns1:Items_> 
       <ns1:InventoryItem> 
        <ns1:Code>testcode</ns1:Code> 
        <ns1:Description>test description</ns1:Description> 
        <ns1:Abccode>test</ns1:Abccode> 
        <ns1:AllocatesAgainstQCPolicy xsi:nil="true"/> 
        <ns1:SafetyStockCU xsi:nil="true"/> 
        <ns1:TemplateItem xsi:nil="true"/> 
        <ns1:MinimumOrderQTY xsi:nil="true"/> 
        <ns1:IsLoadBatch xsi:nil="true"/> 
        <ns1:Weight>10.1</ns1:Weight> 
        <ns1:Volume xsi:nil="true"/> 
        <ns1:Diameter xsi:nil="true"/> 
        <ns1:IsTemporaryItem xsi:nil="true"/> 
        <ns1:IsKitItem xsi:nil="true"/> 
        <ns1:ItemMainCategory>testCategory</ns1:ItemMainCategory> 
        <ns1:IsFragile xsi:nil="true"/> 
        <ns1:IsPackingItem xsi:nil="true"/> 
        <ns1:Depositor>ABC</ns1:Depositor> 
        <ns1:DepositorCode>123</ns1:DepositorCode> 
       </ns1:InventoryItem> 
      </ns1:Items_> 
      <ns1:UserName_>ABC</ns1:UserName_> 
      <ns1:Password_>123123</ns1:Password_> 
      <ns1:SecurityKey_></ns1:SecurityKey_> 
      <ns1:ContinueOnError_>true</ns1:ContinueOnError_> 
     </ns1:DoInventoryItemImport> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

但是,當我從他們的服務定義理解,他們希望有一個SOAP信封像這樣的;

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
     <DoInventoryItemImport xmlns="http://tempuri.org/"> 
      <Items_> 
       <InventoryItem> 
        <Code>testcode</Code> 
        <Description>test description</Description> 
        <Abccode>test</Abccode> 
        <AllocatesAgainstQCPolicy>true</AllocatesAgainstQCPolicy> 
        <SafetyStockCU>1</SafetyStockCU> 
        <TemplateItem>true</TemplateItem> 
        <MinimumOrderQTY>1</MinimumOrderQTY> 
        <IsLoadBatch>true</IsLoadBatch> 
        <Weight>10.1</Weight> 
        <Volume>1</Volume> 
        <Diameter>1</Diameter> 
        <IsTemporaryItem>true</IsTemporaryItem> 
        <IsKitItem>true</IsKitItem> 
        <ItemMainCategory>testCategory</ItemMainCategory> 
        <IsFragile>true</IsFragile> 
        <IsPackingItem>true</IsPackingItem> 
        <Depositor>ABC</Depositor> 
        <DepositorCode>123</DepositorCode> 
       </InventoryItem> 
      </Items_> 
      <UserName_>ABC</UserName_> 
      <Password_>123123</Password_> 
      <SecurityKey_></SecurityKey_> 
      <ContinueOnError_>true</ContinueOnError_> 
     </DoInventoryItemImport> 
    </soap:Body> 
</soap:Envelope> 

其實這些信封包含相同的數據和他們的結構相匹配。但我不知道如何將標籤名稱(如SOAP-ENV)更改爲soap,並刪除「ns1:」之類的前綴。

我想我錯了我的Zend Soap客戶端?

回答

3

我通過重載Zend Soap Client來解決這個問題。我使用str_ireplace函數將'ns1:'替換爲請求變量中的''。然後我使用我的自定義客戶端進行連接。希望這有助於某人。

class My_Client extends Zend_Soap_Client_DotNet{ 

    public function _doRequest(Zend_Soap_Client_Common $client, $request, $location, $action, $version, $one_way = null) 
    { 
     if ($one_way == null) { 
      return call_user_func(array($client,'SoapClient::__doRequest'), str_ireplace('ns1:', '', $request), $location, $action, $version); 
     } else { 
      return call_user_func(array($client,'SoapClient::__doRequest'), str_ireplace('ns1:', '', $request), $location, $action, $version, $one_way); 
     } 
    } 

} 
+0

非常有用。感謝分享。 –