我正在尝试将.net WSDL服务与Zend Soap Client连接起来。我使用下面的代码;
$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'
)
)
));
此代码发送的信封与此信封完全相同;
<?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>
但据我从他们的服务定义中了解,他们想要一个像这样的肥皂信封;
<?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肥皂客户端配置错误了?
答案 0 :(得分:3)
我通过重载Zend Soap Client来解决这个问题。我用str_ireplace函数替换了ns1:&#39;与&#39;&#39;请求变量。然后我使用我的自定义客户端进行连接。希望这对某人有帮助。
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);
}
}
}