2009-01-26 37 views
0

调用一个TCP SoapService我有一个演示SOAP服务它回显请求使用的TcpClient

public class EchoWebService : SoapService 
    { 
     [SoapMethod("Echo")] 
     public string Echo(string request) 
     { 
      Console.WriteLine("Request: {0}", request); 
      return DateTime.Now + Environment.NewLine + request; 
     } 
    } 

服务使用TCP托管,

Uri to = new Uri("soap.tcp://localhost:5696"); 
EndpointReference EPR = new EndpointReference(to); 
SoapReceivers.Add(EPR, new EchoWebService()); 

我可以写我自己的TCP调用服务SoapClient的,

Uri to = new Uri("soap.tcp://localhost:5696"); 
EndpointReference EPR = new EndpointReference(to); 
mysoapclient client1 = new mysoapclient(EPR); 
Console.WriteLine(client1.GetResponse("Hello World")); 

class mysoapclient : SoapClient 
{ 
     public mysoapclient(EndpointReference endpoint) : base(endpoint) { } 
     public string GetResponse(string request) 
     { 

      return base.SendRequestResponse("Echo", 
       request).GetBodyObject(typeof(string)).ToString(); 
     } 
} 

有没有办法来调用它利用tcpclient的服务?我想通过TCP发送原始xml来调用服务并从网络流中读取响应。我尝试使用下面的代码和XML,但它似乎并没有工作。

TcpClient client = new TcpClient("localhost", 5696); 
byte[] request = Encoding.UTF8.GetBytes(xml); 
NetworkStream stream = client.GetStream(); 
stream.Write(request, 0, request.Length); 
byte[] response = new byte[client.ReceiveBufferSize]; 
client.GetStream().Read(response, 0, client.ReceiveBufferSize); 
Console.WriteLine(Encoding.UTF8.GetString(response)); 

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <Echo xmlns="http://tempuri.org/"> 
     <request>Hello World</request> 
    </Echo> 
    </soap:Body> 
</soap:Envelope> 

任何帮助,将不胜感激。

回答

1

您需要将所有二进制文件头填充到SOAP/TCP

参见SUN's SOAP/TCP reference

作为提示,您可以运行tcpdumpwireshark,记录您的SOAP会话并查看您需要填写什么内容。

要记录一个VLAN,使用tcpdump把它捕捉到该文件,并打开该文件与wireshark

+0

我尝试使用Wireshark的(连同所有的黑客提到@ http://wiki.wireshark.org/CaptureSetup /环回),但它不捕获在Windows上的回环流量。 tcpdump捕获了回送流量,但输出没有意义。 – chikak 2009-01-26 10:42:32