Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
XML
<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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="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:
XML
<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[^]
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900