简体   繁体   中英

Bad Request 400 POST WCF Service TEXT/XML (C#)

I need help, I have the following code,

Services is ok, test via SoapUi Image:

Image test soapui here

Error: The remote server returned an error: (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() + " ----");

        }

    }

Please take a glimpse at the require/response information with Fiddler software.
在此处输入图片说明 The body content of the HTTP request and the fields of the transport can be set as shown in the screenshot above. For example, the SOAPAction field, please note that the namespace needs to be added. I suggest that you publish restful style WCF service, and then use httpclient httpwebrequest/webrequest build and send post/get request. See the link below.
How can I use a WCF Service?
https://docs.microsoft.com/en-us/dotnet/framework/wcf/wcf-and-aspnet-web-api
Feel free to let me know if there is anything I can help with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM