【发布时间】:2019-06-07 18:03:22
【问题描述】:
我需要帮助,我有以下代码,
服务没问题,通过 SoapUi Image 测试:
错误: 远程服务器返回错误:(400) Bad Request。
String xmlql = "@<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:con='contact.crm.amsa'><soapenv:Header/><soapenv:Body><con:CreateReclamo><con:request><con:Apellido>as</con:Apellido><con:Asunto>as</con:Asunto><con:Ciudad>asasas</con:Ciudad><con:Email>allanm@xms.cl</con:Email><con:Mensaje>as</con:Mensaje><con:Nombre>as</con:Nombre><con:Pais>as</con:Pais></con:request></con:CreateReclamo></soapenv:Body></soapenv:Envelope>";
byte[] data2 = encoding.GetBytes(xmlql);
String url = "https://amssclsrmprd02:511/WebServices/Contacto.svc";
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
// Preparacion de Request con variables POST / TExt/XML - Credenciales
//HttpWebRequest myRequest =(HttpWebRequest)WebRequest.Create(new Uri("https://amssclsrmprd02:511/WebServices/Contacto.svc"));
myRequest.Method = "POST";
myRequest.ContentType = "text/xml; charset=utf-8";
myRequest.Headers.Add("SOAPAction", "CreateReclamo");
myRequest.ContentLength = data2.Length;
myRequest.Credentials = new NetworkCredential("crm","amsa");
Umbraco.Core.Logging.LogHelper.Info(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "******************** response ----");
//escribo en Webservicesa
using (Stream putStream = myRequest.GetRequestStream())
{
//putStream.Write(bytes, 0, bytes.Length);
putStream.Write(data2, 0, data2.Length);
using (HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
Umbraco.Core.Logging.LogHelper.Info(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "******************** response " + reader.ReadToEnd() + " ----");
}
}
【问题讨论】:
-
您不使用服务参考是否有原因?即使您只能临时使用服务引用进行测试,您也可以trace System.Net 来查看在线上的 xml 并将其与 SoapUI 进行比较,以便您了解需要更改的内容。
-
在 umbraco 项目中工作的服务参考?
-
我不熟悉umbraco,也许你应该用它来标记问题。但是您可以使用服务引用创建一个丢弃的控制台应用程序,如果您只是查看跟踪,则无需在应用程序中执行此操作。
-
按照this的回答开启你的服务器端日志,看看他们怎么说
标签: c# wcf xmlhttprequest httpresponse