1)我在本地IIS 5.1上部署了WCF服務:WCF - 錯誤:傳出消息的消息版本(Soap12(http://www.w3.org/2003/05/soap-envelope)
接口:
[OperationContract(Action = Service.RequestAction, ReplyAction = Service.ReplyAction)]
Message SetData(Message requestXml);
實現:
public const string ReplyAction = "http://localhost/AsurReceiveData/Message_ReplyAction";
public const string RequestAction = "http://localhost/AsurReceiveData/Message_RequestAction";
public Message SetData(Message requestXml)
{
using (StreamWriter writer = File.CreateText(@"E:\Projekti\WCF\Parus\AsurReplicData\Parus\Body.xml"))
{
writer.WriteLine(requestXml.ToString());
}
Message response = Message.CreateMessage(MessageVersion.Default, ReplyAction, requestXml.ToString());
return response;
}
Web.config文件:
<system.serviceModel>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://localhost:80/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior name="Parus.ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost/AsurReceiveData/Service.svc"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<MyInspector />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="Parus.ServiceBehavior" name="Parus.Service">
<endpoint address="http://localhost/AsurReceiveData/Service.svc" binding="basicHttpBinding" contract="Parus.IService">
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
<extensions>
<behaviorExtensions>
<add name="MyInspector" type="Parus.MessageInspectorExtension, Parus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
</system.serviceModel>
2)客戶端看起來如下:
ServiceClient client = new ServiceClient();
string RequestAction = "http://localhost/AsurReceiveData/Message_RequestAction";
Message request = Message.CreateMessage(MessageVersion.Default, RequestAction, "Test message");
Message reply = client.SetData(request);
Web.config文件:
<binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<endpoint address="http://localhost/AsurReceiveData/Service.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
contract="ServiceReference.IService" name="BasicHttpBinding_IService" />
當我運行客戶端,以下錯誤消息出現:
The message version of the outgoing message (Soap12 (http://www.w3.org/2003/05/soap-envelope) Addressing10 (http://www.w3.org/2005/08/addressing)) does not match that of the encoder (Soap11 (http://schemas.xmlsoap.org/soap/envelope/) AddressingNone (http://schemas.microsoft.com/ws/2005/05/addressing/none)). Make sure the binding is configured with the same version as the message.
如何我可以使它工作嗎?
我知道,但如果我究竟應該設置這些參數,在web.config文件中或在代碼中,哪些我應該設置嗎? – tesicg
錯誤消息來自客戶端,我已經嘗試在消息創建方法中設置不同的選項,但沒有任何幫助。 – tesicg