当我使用下面的方法向asmx服务发送xml请求时,它工作正常,唯一的区别是内容类型是application/soap+xml
。我收到错误:400 Bad Request。以下是我在下面使用的方法,通过HTTP Post将请求发送到WCF服务:
private static void SendRequest(string request)
{
var req = (HttpWebRequest) WebRequest.Create("http://urltoservice.svc");
req.ContentType = "text/xml";
req.Method = "POST";
using (var stm = req.GetRequestStream())
{
using (var stmw = new StreamWriter(stm))
{
stmw.Write(request);
}
}
byte[] myData;
using (var webResponse = req.GetResponse())
{
var responseStream = webResponse.GetResponseStream();
myData = ReadFully(responseStream);
}
// Do whatever you need with the response
string responseString = Encoding.ASCII.GetString(myData);
}
似乎把它抛到了一行:var webResponse = req.GetResponse()