none
Convert WCF Net.tcp bindings to HTTP RRS feed

  • Question

  • Hi,

    I have some services written in WCF that use net.tcp, we run a ZXTM load balancer that can only manage http not net tcp.  Is it easy to change the binding in the web.config of a .net service without editing the code base of the wcf application?

    A few ideas or pointers would be great...

    Thanks


    Alter De Ruine

    Thursday, January 17, 2013 4:46 PM

Answers

  • Hi James,

    You wrote on 17/01/2013 :

    I have some services written in WCF that use net.tcp, we run a ZXTM load balancer that can only manage http not net tcp.  Is it easy to change the binding in the web.config of a .net service without editing the code base of the wcf application?

    One of the amazing thing of WCF is that the binding is defined in the configuration file of the service and the service implementation does not know anything of the binding, thus you can change it without affecting in any way the service code.

    .m



    blog @ //milestone.topics.it
    Thursday, January 17, 2013 5:03 PM

All replies

  • Hi James,

    You wrote on 17/01/2013 :

    I have some services written in WCF that use net.tcp, we run a ZXTM load balancer that can only manage http not net tcp.  Is it easy to change the binding in the web.config of a .net service without editing the code base of the wcf application?

    One of the amazing thing of WCF is that the binding is defined in the configuration file of the service and the service implementation does not know anything of the binding, thus you can change it without affecting in any way the service code.

    .m



    blog @ //milestone.topics.it
    Thursday, January 17, 2013 5:03 PM
  • Assuming your application is using an app.config or web.config for wcf configuration it's very simple.

    As in the example below:

    <configuration>
      <system.serviceModel>
        <services>
          <service name=”ChatService”>
            <endpoint
               address=”http://localhost:8080/chat”
               binding=”basicHttpBinding”
               contract=”IChat”/>
            <endpoint
               address=”http://localhost:8080/chat/secure”
               binding=”wsHttpBinding”
               contract=”IChat”/>
            <endpoint
               address=”net.tcp://localhost:8081/chat”
               binding=”netTcpBinding”
               contract=”IChat”/>
          </service>
        </services>
      </system.serviceModel>
    </configuration>

    from http://msdn.microsoft.com/en-us/magazine/cc163394.aspx

    You need to create an endpoint with appropriate binding type. And a binding of an http type.

    eg:

    <bindings>
          <basicHttpBinding>
            <binding name=”basicConfig1” messageEncoding=”Text”>
              <security mode=”Transport”/>
            </binding>
            <binding name=”basicConfig2” messageEncoding=”Mtom”>
              <security mode=”Transport”/>
            </binding>
          </basicHttpBinding>
          <wsHttpBinding>
            <binding name=”wsConfig” transactionFlow=”true”>
              <security mode=”TransportWithMessageCredential”>
                <message clientCredentialType=”UserName”/>
              </security>
              <reliableSession enabled=”true” ordered=”true”/>
            </binding>
          </wsHttpBinding>
          <netTcpBinding>
            <binding name=”tcpConfig” transactionFlow=”true”
                transactionProtocol=”WSAtomicTransactionOctober2004”>
              <security mode=”None”/>
              <reliableSession enabled=”true” />
            </binding>
          </netTcpBinding>
        </bindings>

    See the link for a little more information ;)

    Thursday, January 17, 2013 6:10 PM