Interop with simple socket client
Hi,
I want to develop a WCF service to communicate to a simple socket cliet like
using
System;using System.IO;
using
System.Net;using
System.Text;using
System.Net.Sockets;public
class clnt { public static void Main() { try { TcpClient tcpclnt = new TcpClient(); Console.WriteLine("Connecting.....");tcpclnt.Connect(
"localhost",8999); // use the ipaddress as in the server program Console.WriteLine("Connected"); Console.Write("Enter the string to be transmitted : "); String str=Console.ReadLine(); Stream stm = tcpclnt.GetStream(); ASCIIEncoding asen= new ASCIIEncoding(); byte[] ba=asen.GetBytes(str); Console.WriteLine("Transmitting.....");stm.Write(ba,0,ba.Length);
byte[] bb=new byte[100]; int k=stm.Read(bb,0,100); for (int i=0;i<k;i++) Console.Write(Convert.ToChar(bb[ i ]));tcpclnt.Close();
}
catch (Exception e) { Console.WriteLine("Error..... " + e.StackTrace);}
}
}
What are need to be done in tcpbinding? Can it be done? What is the example I can study?
Regards,
Reggie
Answers
On the server side, the tcp message is expected to be conformant to .Net Message Framing - this is not a published format. You are just sending raw bytes that do not conform to the format the server is expecting the messages in. The NetTcpBinding is not interoperable - by design - it is designed for optimized WCF <->WCF communication.
Do you have to use sockets directly in your client or could your client be WCF and use the NetTcpBinding?
Hope that helps,
Kavita
All Replies
On the server side, the tcp message is expected to be conformant to .Net Message Framing - this is not a published format. You are just sending raw bytes that do not conform to the format the server is expecting the messages in. The NetTcpBinding is not interoperable - by design - it is designed for optimized WCF <->WCF communication.
Do you have to use sockets directly in your client or could your client be WCF and use the NetTcpBinding?
Hope that helps,
Kavita
Hi,
The raw socket client is not built in .NET. It is actually a Adobe Flex AS3 client that can use TCP socket to communicate in XML text or binary. Do I have to implement a custom binding to achieve interoperability? I can not consider sessionless transport like HTTP, the server has to handle persistent multi TCP session.
The plan is to build a communication server for Adobe Flash/Flex client in WCF. Is this achievable?
Regards,
Reggie
- I see. Yeah you'll need to write a custom binding on the server side which is basically NetTcpBinding but with a custom encoder. The WSE TCP interop sample is a good example where the wire format framing had to be changed to talk to WSE.
- Hello,
I have attempted to compile the WSE TCP interop sample, and have run into difficultly as it seem the "MessageBodyAttribute" type has changed to "MessageBodyMemberAttribute" since the release of the sample. Any idea how to make it compile?
Thank you,
-Christie I have the same problem. I hade Adobe Flash client with socket and a WCF service with net.tcp.
Doese anyone know where I can find the code sample "WSE TCP"?

