我在使用.NET C#发布SOAP请求时遇到问题,错误消息是->由于EndpointDispatcher上的ContractFilter不匹配,因此无法在接收方处理带有操作''的消息。这可能是由于合同不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配造成的。检查发送方和接收方具有相同的合同和绑定(包括安全性要求,例如消息,传输,无)。
XmlDocument doc = new XmlDocument();
string xmlDoc = ReadXML(@"..\..\PayLoad.xml");
doc.LoadXml(xmlDoc);
//Create web request
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://teslaperf.sandbox.operations.dynamics.com/soap/services/TSLAJournalUploadConcurGroup");
req.Headers.Add("Authorization", OAuthHelper.GetAuthenticationHeader(true));
req.ContentType = "text/xml;charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";
//
using (Stream stream = req.GetRequestStream())
{
doc.Save(stream);
}
try
{
using (WebResponse response = req.GetResponse())
{
using (StreamReader rd = new StreamReader(response.GetResponseStream()))
{
string soapResult = rd.ReadToEnd();
Console.WriteLine(soapResult);
}
}
}
catch (WebException e)
{
if (e.Status == WebExceptionStatus.ProtocolError)
{
WebResponse resp = e.Response;
using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
{
Console.WriteLine(sr.ReadToEnd());
}
}
}