错误的请求400 POST WCF服务TEXT / XML(C#)

时间:2019-01-13 14:29:08

标签: c# wcf xmlhttprequest httpresponse

我需要帮助,我有以下代码,

服务还可以,请通过SoapUi映像进行测试:

Image test soapui here

错误: 远程服务器返回错误:(400)错误的请求。

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() + " ----");

        }

    }

1 个答案:

答案 0 :(得分:0)

请使用Fiddler软件浏览需求/响应信息。
enter image description here 可以如上面的屏幕快照所示设置HTTP请求的正文内容和传输字段。例如,在SOAPAction字段中,请注意,需要添加名称空间。我建议您发布宁静风格的WCF服务,然后使用httpclient httpwebrequest / webrequest构建并发送发布/获取请求。请参阅下面的链接。
How can I use a WCF Service?
https://docs.microsoft.com/en-us/dotnet/framework/wcf/wcf-and-aspnet-web-api
随时让我知道是否有什么可以帮助您的。