使用webclient调用webservice方法 [英] Using webclient to call a webservice method
本文介绍了使用webclient调用webservice方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里有解决方案
Here am getting solution
UploadStringCompleted: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmln
s:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/
2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body
><HelloWorldResponse xmlns="http://tempuri.org/"><HelloWorldResult>Hello Karthik
mushyam</HelloWorldResult></HelloWorldResponse></soap:Body></soap:Envelope>
我怎么能只获取Hello karthik作为被调用方法的输出
How can i get only Hello karthik as output from the called method
static void Main(string[] args)
{
WebClient client = new WebClient();
string request1 = "<soap:Envelope\r\n xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\r\n xmlns:xsd='http://www.w3.org/2001/XMLSchema'\r\n xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>\r\n <soap:Body><HelloWorld xmlns=\"http://tempuri.org/\"><name>Karthik mushyam</name></HelloWorld></soap:Body></soap:Envelope>";
client.Headers.Add(HttpRequestHeader.ContentType, "text/xml");
client.Headers.Add("SOAPAction", "http://tempuri.org/HelloWorld");
client.UploadStringCompleted += new UploadStringCompletedEventHandler(client_UploadStringCompleted);
client.UploadStringAsync(new Uri("http://localhost:52375/MyFirstWebService/Service.asmx"), request1);
Console.ReadLine();
}
static void client_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
{
Console.WriteLine("UploadStringCompleted: {0}", e.Result);
}
推荐答案
结果是XML
,所以解析它并找到HelloWorldResult
节点值。
参考 - 用C#解析XML [ ^ ]为一个例子。
As the result is inXML
, so parse it and find theHelloWorldResult
node value.
Refer - Parsing XML in C#[^] for one example.
这篇关于使用webclient调用webservice方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文