当我使用下面的方法向 asmx 服务发送 xml 请求时,它工作正常,唯一的区别是内容类型是application/soap+xml
. 我收到错误:400 错误请求。这是我在下面使用的通过 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()