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>
任何幫助,將不勝感激。
我嘗試使用Wireshark的(連同所有的黑客提到@ http://wiki.wireshark.org/CaptureSetup /環回),但它不捕獲在Windows上的迴環流量。 tcpdump捕獲了回送流量,但輸出沒有意義。 – chikak 2009-01-26 10:42:32