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

问题描述 投票:-1回答:1

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

服务还可以,通过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>[email protected]</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() + " ----");

        }

    }
c# wcf xmlhttprequest httpresponse
1个回答
0
投票

请用Fiddler软件一瞥需求/响应信息。 enter image description here可以设置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 如果有什么我可以帮忙,请随时告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.