I wrote a
WCF service and a
WCF client application in .NET 4.5. They communicated each other using
WebSocket and worked very well. As we know,
Binary SOAP message encoding was used by default. But I changed it to
Text SOAP message encoding for some purpose. The service and application still worked well after the change. Then I used
Microsoft Network Monitor 3.4 (NetMon.exe) to check the messages. Strangely, I found all
Request messages were still encoded while all
Response messages were Text messages which I wanted.
Could someone please tell me what happened?
P.S. The WCF service's
web.config is as the following code piece:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add scheme="http" binding="netHttpBinding" bindingConfiguration="textWSHttpBinding"/>
<add scheme="https" binding="netHttpsBinding" bindingConfiguration="textWSHttpsBinding"/>
</protocolMapping>
<bindings>
<netHttpBinding>
<binding name="textWSHttpBinding" messageEncoding="Text"/>
</netHttpBinding>
<netHttpsBinding>
<binding name="textWSHttpsBinding" messageEncoding="Text"/>
</netHttpsBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
The app.config of the WCF client application is as the following code piece:
<system.serviceModel>
<bindings>
<netHttpBinding>
<binding name="NetHttpBinding_IWSChatService" messageEncoding="Text">
<webSocketSettings transportUsage="Always" />
</binding>
</netHttpBinding>
</bindings>
<client>
<endpoint address="ws://localhost/WcfWSChat/WSChatService.svc"
binding="netHttpBinding" bindingConfiguration="NetHttpBinding_IWSChatService"
contract="WSChatServiceReference.IWSChatService" name="NetHttpBinding_IWSChatService" />
</client>
</system.serviceModel>
The screenshot of the
Request body in NetMon.exe is as the below:
Request Body[
^]
The screenshot of the
Response body in NetMon.exe is as the below:
Response Body[
^]