【问题标题】:Bad Request 400 POST WCF Service TEXT/XML (C#)错误请求 400 POST WCF 服务文本/XML (C#)
【发布时间】:2019-06-07 18:03:22
【问题描述】:

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

服务没问题,通过 SoapUi Image 测试:

Image test soapui here

错误: 远程服务器返回错误:(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


【解决方案1】:

请使用 Fiddler 软件查看需求/响应信息。
HTTP 请求的正文内容和传输的字段可以如上面的屏幕截图所示进行设置。例如 SOAPAction 字段,请注意需要添加命名空间。我建议你发布restful风格的WCF服务,然后使用httpclient httpwebrequest/webrequest构建并发送post/get请求。请参阅下面的链接。
How can I use a WCF Service?
https://docs.microsoft.com/en-us/dotnet/framework/wcf/wcf-and-aspnet-web-api
如果有什么我可以帮忙的,请随时告诉我。

【讨论】:

    猜你喜欢
    • 2012-04-27
    • 2015-11-24
    • 1970-01-01
    • 2011-09-29
    • 2014-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多