Ask a questionAsk a question
 

AnswerInterop with simple socket client

  • Wednesday, December 06, 2006 1:04 AMReggie Chen Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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

  • Friday, December 08, 2006 1:28 PMKavita Kamani - MSFTMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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

  • Friday, December 08, 2006 1:28 PMKavita Kamani - MSFTMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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

  • Friday, December 08, 2006 5:42 PMReggie Chen Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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

  • Friday, December 08, 2006 11:58 PMKavita Kamani - MSFTMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.
  • Monday, February 19, 2007 1:45 PMChristie_Wilson Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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
  • Tuesday, January 29, 2008 3:08 PMdevZebra.com Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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"?