1

There is a service that accepts data as an Xml string.

I'm trying to send xml as a serialized string to this service, however I'm getting a 400 error code. What am I doing wrong?

My class for request:

public class AltoTrackClient
{
    //private static string _url = "http://ws4.altotrack.com";
    //private static string _action = "/WSPosiciones_WalmartMX/WSPosiciones_WalmartMX.svc?wsdl";

    public static string ProcessXml(string xmlString)
    {           
        HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://ws4.altotrack.com/WSPosiciones_WalmartMX/WSPosiciones_WalmartMX.svc?singleWsdl");

        byte[] requestInFormOfBytes = System.Text.Encoding.UTF8.GetBytes(xmlString);
        request.Method = "POST";
        request.ContentType = "text/xml;charset=utf-8";
        request.ContentLength = requestInFormOfBytes.Length;
        Stream requestStream = request.GetRequestStream();
        requestStream.Write(requestInFormOfBytes,0, requestInFormOfBytes.Length);
        requestStream.Close();
        string recievedResponse;            
        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {
            using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default))
            {
                recievedResponse = reader.ReadToEnd();
            }
        }
        return recievedResponse;
    }
}
4

1 Answer 1

1

Maybe it's a little too late to answer this question, since it's been more than 1 year and 9 months from the date this question was asked, but I have some clues on how to solve this issue, if that may help you or someone else.

I worked recently on a project in which I needed to develop a process that communicated with Altotrack web service. I was trying to send some requests to this web service and in the end I just ended up receiving error 400 the same way that it's happening with you. Their documentation is really confusing and unhelpful, to say the least.

After some analyzing and attempts, I find out how the parameters of the POST request must be set so the web service replies with a success message:

URL: http://ws4.altotrack.com/WSPosiciones_WalmartMX/WSPosiciones_WalmartMX.svc

Headers: Content-Type : text/xml; charset=utf-8 SOAPAction : http://tempuri.org/IServicePositions/ProcessXML

Request payload: `

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
  <soapenv:Body>
    <tem:ProcessXML>
      <tem:xmlSerializado>
        &lt;registro&gt;
          &lt;systemUser&gt;AltoWS&lt;/systemUser&gt;
          &lt;password&gt;$Alt0WS&lt;/password&gt;
          &lt;movil&gt;
            &lt;proveedor&gt;My&lt;/proveedor&gt;
            &lt;dominio&gt;ABC1234&lt;/dominio&gt;
            &lt;nroSerie&gt;12345678&lt;/nroSerie&gt;
            &lt;fechaHoraEvento&gt;25-10-2019 12:34:56&lt;/fechaHoraEvento&gt;
            &lt;fechaHoraRecepcion&gt;25-10-2019 12:34:56&lt;/fechaHoraRecepcion&gt;
            &lt;latitud&gt;-22.215328&lt;/latitud&gt;
            &lt;longitud&gt;-49.6559497&lt;/longitud&gt;
            &lt;altitud&gt;666&lt;/altitud&gt;
            &lt;velocidad&gt;20&lt;/velocidad&gt;
            &lt;rumbo&gt;180&lt;/rumbo&gt;
            &lt;codigo&gt;0&lt;/codigo&gt;
          &lt;/movil&gt;
        &lt;/registro&gt;
      </tem:xmlSerializado>
    </tem:ProcessXML>
  </soapenv:Body>
</soapenv:Envelope>

`

Of course, in the request payload, I added spaces only to be more legible. You can remove them without any issue if you so desire to decrease the size of the request payload.

It was a long time ago I worked with C#, but I analyzed the portion of your code and I'd say that the value that came stored in the parameter xmlString in the method ProcessXml isn't in the format expected by the web service, therefore returning error 400 upon request. That's what was happening to me too.

I hope that helps.

Sign up to request clarification or add additional context in comments.

1 Comment

I don't know how you solved it, but it works! the documentation is a total mess. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.