-1

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

        }

    }
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Fernando
  • 1
  • 1
  • Is there a reason you are not using a Service Reference? Even if you can only use a service reference temporarily for testing you can [trace System.Net](https://learn.microsoft.com/en-us/dotnet/framework/network-programming/how-to-configure-network-tracing) to see what xml is going on the wire and compare it to SoapUI so you have an idea what you need to change. – Crowcoder Jan 13 '19 at 14:37
  • Service references working in umbraco project ? – Fernando Jan 13 '19 at 15:51
  • I'm not familiar with umbraco, maybe you should tag the question with that. But you can create a throw away console app with the service reference, you don't need to do it in your application if you're just looking at the trace. – Crowcoder Jan 13 '19 at 16:32
  • Turn on your server side logs as per [this](https://stackoverflow.com/questions/18512507/wcf-service-how-to-find-server-logs-to-understand-error) answer, let's see what they say – Francesco B. Jan 13 '19 at 19:20

1 Answers1

0

Please take a glimpse at the require/response information with Fiddler software.
enter image description here 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://learn.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.

Abraham Qian
  • 7,117
  • 1
  • 8
  • 22