【发布时间】:2017-07-19 13:20:21
【问题描述】:
我在服务器上运行了一个 SOAP 服务,我需要在服务器端连接到他并将结果检索到客户端,我知道我可以将 http 方法与控制器和模型相关联,但我不太了解好吧,我如何实现一个获取请求,并在它没有直接与模型关联时给它我想要的名称。
目前我有这个:
public class DefaultController : ApiController
{
[HttpGet]
public void ProjectName()
{
var _url = "http://cmf-sharepoint/ims/Processes/_vti_bin/lists.asmx";
var _action = "http://schemas.microsoft.com/sharepoint/soap/GetListItems";
XmlDocument soapEnvelopeXml = CreateSoapEnvelope();
HttpWebRequest webRequest = CreateWebRequest(_url, _action);
InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);
// begin async call to web request.
IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
// suspend this thread until call is complete. You might want to
// do something usefull here like update your UI.
asyncResult.AsyncWaitHandle.WaitOne();
// get the response from the completed web request.
string soapResult;
using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
{
using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
{
soapResult = rd.ReadToEnd();
}
Console.Write(soapResult);
}
}
private static HttpWebRequest CreateWebRequest(string url, string action)
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Headers.Add("SOAPAction", action);
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
return webRequest;
}
private static XmlDocument CreateSoapEnvelope()
{
XmlDocument soapEnvelop = new XmlDocument();
soapEnvelop.LoadXml(@"<?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>'<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'><listName>8e82569a-27b1-47ec-a557-0cc01e250e4f</listName>'<query><Query><Where><Eq><FieldRef Name='Project_x0020_Status'/> <Value Type='Choice'>Active</Value></Eq></Where><OrderBy><FieldRef Name='Title' Ascending='TRUE' /></OrderBy></Query></query></GetListItems></soap:Body></soap:Envelope>");
return soapEnvelop;
}
private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
{
using (Stream stream = webRequest.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
}
}
}
我需要在 get 请求中获取 SOAP resonde 有什么帮助吗?目前我无法访问该路线
【问题讨论】:
标签: c# asp.net rest asp.net-web-api soap