【发布时间】:2011-06-22 05:37:10
【问题描述】:
是否可以通过 WebClient.DownloadString() 从我的 WebService.asmx/Method 获取数据?或者如何在不向我的项目添加 WebService 引用的情况下仅通过代码获取数据?
【问题讨论】:
标签: .net asp.net web-services
是否可以通过 WebClient.DownloadString() 从我的 WebService.asmx/Method 获取数据?或者如何在不向我的项目添加 WebService 引用的情况下仅通过代码获取数据?
【问题讨论】:
标签: .net asp.net web-services
public XmlDocument SubmitDocument1(XmlDocument xDoc, string URL)
{
try
{
// get the data from the xml document into a byte stream
Byte[] bdata = System.Text.Encoding.ASCII.GetBytes(xDoc.OuterXml);
// instantiate a web client
WebClient wc = new WebClient();
// add appropriate headers
wc.Headers.Add("Content-Type", "text/xml");
// add default Credentials
wc.Credentials = CredentialCache.DefaultCredentials;
// send data to server, and wait for a response
Byte[] bresp = wc.UploadData(URL, bdata);
// read the responses
string resp = System.Text.Encoding.ASCII.GetString(bresp);
XmlDocument xresp = new XmlDocument();
xresp.LoadXml(resp);
// return the xml document response from the server
return xresp;
}
catch
{
}
}
【讨论】: