Using TcpClient to access a WCF endpoint

Hi,

I have a created a basic WCF service with fallowing contract.

[ServiceContract]

public interface IDumpService

{

[OperationContract(Action = "*", IsOneWay = true)]

void Dump(Message msg);

[OperationContract]

void DumpString(string msg);

}

I used NetTcpBinding or CustomBinding ( with TcpTransportBindingElement & BinaryMessageEncodingBindingElement )

Now on the client side, I'm doing following:

static void SocketClient()

{

string soapMessage =

string.Format("<s:Envelope xmlns:s=\"{0}\" xmlns:a=\"{1}\"><s:Header>{2}</s:Header><s:Body/> </s:Envelope>",

"http://www.w3.org/2003/05/soap-evelope", "http://schemas.xmlsoap.org/ws/2004/08/addressing", "<a:Action s:mustUnderstand=\"1\">DefAction</a:Action><a:To s:mustUnderstand=\"1\">net.tcp://localhost:8080/</a:To>");

TcpClient clnt = new TcpClient();

try

{

clnt.Connect("localhost", 8080);

byte[] buffer =

Encoding.Default.GetBytes(soapMessage);

clnt.GetStream().Write(buffer, 0, buffer.Length);

byte[] recvBuffer = new byte[clnt.ReceiveBufferSize];

clnt.GetStream().Read(recvBuffer, 0, clnt.ReceiveBufferSize);

string result = Encoding.Default.GetString(recvBuffer);

clnt.Close();

}

}

This doesn't seems to work. Service closes my connection after it recieves first message.

Now, If I run WCF client against that service, it looks like that there is packet exchange between client/service confirming that specific endpoint exists or not.

After that orignal SOAP mesage exchanges starts.

Does anybody knows this protocol Or if you give me pointers to some related information.

I'm doing all this to learn how WCF messaging work on different transports.

Many thanks

Regards,

Zulfiqar



Answer this question

Using TcpClient to access a WCF endpoint

  • kentz

    Hi Zulfiqar, I don't think you'll have much luck trying to hand-construct messages that will work with the NetTcpBinding. If you're interested in learning more about our transport stack, I recommend you check out Nicholas Allen's excellent blog [1], which includes all kinds of wonderful data on transports, channels, hosting, and the rest of WCF's underbelly.

    Cheers,

    JJustice [MSFT]

    [1] http://blogs.msdn.com/drnick/default.aspx


  • Using TcpClient to access a WCF endpoint