none
WCF Client talking to tcp socket server RRS feed

  • Question

  • Hi,

    I have  a third party service listening on a socket.

    I would like to be able to talk to it using a WCF based client.

    I've just read there are issues with netTCP, in that it is not compliant with standard TCP sockets(!!!)

    Is this the same as saying the tcpTransportElement cannot be used to talk to a TCP socket?

    The socket (server) requires a newline after the request xml (POX) in order to recognize the end of the request. It then replies on the same socket.

    I'm using a custom formatting behaviour to ensure the correct message is sent, however I don't think the connection is establishing successfully.

    My customBinding looks like this:

                <customBinding>
                    <binding name="NewBinding0">
                        <textMessageEncoding messageVersion="None" writeEncoding="utf-16" />
                        <tcpTransport />
                    </binding>
                </customBinding>

    Is the tcpTransportElement up to the job? How should it be configured?

    Thanks

    Martin

    Tuesday, April 21, 2015 3:39 PM

All replies

  • The key decision is whether or not to make the WCF service conform to the socket client or whether to make the socket client conform to the WCF service.

    It will be simplest to attempt to conform to the WCF service, rather than trying to implement something custom within WCF, which is never easy.  At the bottom of the Other Resources section below you will see a link that describes the message inspection that is necessary in order to attempt to conform to a WCF service.

    Having said that, .NET sockets do not natively communicate with WCF.

    Any attempt to do so will require custom programming on the WCF side of things. 

    Whether you are using TcpClient or raw sockets in .NET to connect to and communicate with WCF does not matter.  Any such interoperability must be handled with custom logic within WCF.  Note that Net.Tcp is a custom transport protocol.  It is not technically using TCP in the same way that the TcpClient is.

    For example, UDP is very commonly used by socket servers in the Linux world.  WCF does not provide a built-in UDP transport.  However, there is a UDP sample for WCF that implements UDP for WCF.  Unfortunately, that sample does not illustrate communicating to and from a non-WCF UPD socket server.

    I have an outstanding question that is rather detailed where I explain my effort to get sample code to generically be testable for using UDP...

    http://stackoverflow.com/questions/484717/error-externally-testing-wcf-udp-custom-transport-channel-sample-from-the-windows

    Nobody has answered my question yet.  So, if you succeed in making this work, I am very interested.  My case was driven by a desire for the WCF Service to be able to call out to a UDP socket server running on Linux without having to clutter my service with non-WCF coding.  I don't want to mix approaches.

    Other Resources...


    I sale myself ONLY half CNY!

    Wednesday, April 22, 2015 6:33 AM
  • Thanks for your response.

    My scenario is a socket based service with WCF client, rather than WCF service with socket based client.

    Thanks

    Martin

    Wednesday, April 22, 2015 6:57 AM