我正在开发一个将由政府机构使用的 WCF 服务。由于他们将访问由不同承包公司托管的相同服务,因此他们指定了消息的确切外观(因此,他们只会更改 URL 以访问每个公司的服务)。
所以,对于这个方法:
sbyte Execute(int Id1, short Id2, string Id3, string Id4, string Value)
他们希望我们完全接受以下 SOAP 消息:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http:/
/www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/
XMLSchema">
<SOAP-ENV:Body>
<m:Execute xmlns:m="http://tempuri.org/">
<m:Id1>1</m:Id1>
<m:Id2>2</m:Id2>
<m:Id3>3</m:Id3>
<m:Id4>4</m:Id4>
<m:Value></m:Value>
</m:Execute>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我们的回应必须是:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ExecuteResponse xmlns="http://tempuri.org/">
<ExecuteResult>
<res>0</res>
</ExecuteResult>
</ExecuteResponse>
</soap:Body>
</soap:Envelope>
现在,我当前服务的消息,使用 binding="basicHttpBinding" 并使用我的测试客户端(以及 WCF 测试客户端工具),如下所示:
要求:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/ISomeService/Execute</Action>
</s:Header>
<s:Body>
<Execute xmlns="http://tempuri.org/">
<Id1>0</Id1>
<Id2>0</Id2>
<Id3>0</Id3>
<Id4>0</Id4>
<Value>0</Value>
</Execute>
</s:Body>
</s:Envelope>
回复:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header />
<s:Body>
<ExecuteResponse xmlns="http://tempuri.org/">
<ExecuteResult>1</ExecuteResult>
</ExecuteResponse>
</s:Body>
</s:Envelope>
所以,我的问题是:我应该改变什么,让我的服务使用 SOAP 消息,如
“<SOAP-ENV:信封 xmlns:SOAP- ... > <SOAP-ENV:Body>”
而不是使用...
<s:信封 .... > <s:Header />
我尝试了几种绑定、自定义配置等,但我无法让它看起来一样。
这是我当前的配置,使用建议的 customBinding:
<system.serviceModel>
<services>
<service name="Test.SomeService">
<endpoint binding="customBinding" bindingConfiguration="Soap11Binding"
contract="Test.ISomeService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<customBinding>
<binding name="Soap11Binding">
<textMessageEncoding messageVersion="Soap11" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<httpTransport allowCookies="true" />
</binding>
</customBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
任何线索任何人?谢谢!