我正試圖與一個Web服務接口。我發佈了一個SOAP Evelolpe,它返回一個SOAP響應。如何在沒有WebRequest的情況下使用WCF服務?
我能夠發佈到服務並獲得響應使用Web請求和Response.But我想用WCF來做到這一點。可以請一些身體幫助我實現這一目標。
我的HTTP帖子:
public string HttpPost (string uri, string parameters)
{
WebRequest webRequest = WebRequest.Create (uri);
webRequest.ContentType = "application/soap+xml; charset=utf-8";
webRequest.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes (parameters);
Stream os = null;
try
{ // send the Post
webRequest.ContentLength = bytes.Length;
os = webRequest.GetRequestStream();
os.Write (bytes, 0, bytes.Length); //Send it
}
try
{ // get the response
WebResponse webResponse = webRequest.GetResponse();
if (webResponse == null)
{ return null; }
StreamReader sr = new StreamReader (webResponse.GetResponseStream());
return sr.ReadToEnd().Trim();
}
return null;
}
此外,請參閱http://stackoverflow.com/tags/wcf/info – 2010-11-08 20:33:00