I am writing application where in the requirement I have to communicate with one device witch send SOAP message over UDP. I am using .Net UDPClient class to communicate with this device. I am 开发者_StackOverflowreceiving reply from this in UDPClient but I am getting that as Byte[] array. How I can convert this to SoapMessage object ?
public void ReceiveCallback(IAsyncResult ar)
{
UdpClient udpClient = (UdpClient)((UdpState)(ar.AsyncState)).udpClient;
IPEndPoint ipEndpt = (IPEndPoint)((UdpState)(ar.AsyncState)).ipEndpt;
Byte[] receiveBytes = udpClient.EndReceive(ar, ref ipEndpt);
string receiveString = Encoding.ASCII.GetString(receiveBytes);
//Here receiveString I want to convert to SoapMessage
BeginReceive();
}
I would recommend using WCF to generate a client for you and implement your own channel to handle the communication from and to the client. You should be able to hook up your code. Ofcourse most socket communication is already done by WCF so you dont really need your code in the first place when using WCF.
see:
http://msdn.microsoft.com/en-us/library/ms789050.aspx
This MSDN article shows how to build a UDP transport based binding for WCF which you can use for your client. Assuming you have access to the WSDL for the service, building and configuring this UDP binding is worthwhile because it will handle all the serialization/deserialization for you. The article code is available as part of the WCF/WF samples for .NET 4 so you can get going by just downloading and installing the samples.
If you don't have access to the WSDL then at least you can peek at the sample code to see how to handle the UdpClient stuff.
精彩评论