有一项服务接受数据作为Xml字符串。
我正在尝试将xml作为序列化字符串发送到此服务,但是我收到了400错误代码。我在做什么错?
我的要求课程:
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;
}
}
也许回答这个问题有点为时已晚,因为距提出该问题的日期已经超过1年零9个月了,但是如果有什么帮助,您可以从中找到一些解决方法的线索其他。
我最近从事的一个项目需要开发与Altotrack Web服务通信的流程。我试图向该Web服务发送一些请求,但最终我还是收到了与您发生的错误相同的错误400。至少可以说,他们的文档确实令人困惑且无益。
经过一些分析和尝试后,我发现必须如何设置POST请求的参数,以便Web服务以成功消息答复:
URL:http://ws4.altotrack.com/WSPosiciones_WalmartMX/WSPosiciones_WalmartMX.svc
标题:
Content-Type : text/xml; charset=utf-8
SOAPAction : http://tempuri.org/IServicePositions/ProcessXML
请求有效负载:`
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Body>
<tem:ProcessXML>
<tem:xmlSerializado>
<registro>
<systemUser>AltoWS</systemUser>
<password>$Alt0WS</password>
<movil>
<proveedor>My</proveedor>
<dominio>ABC1234</dominio>
<nroSerie>12345678</nroSerie>
<fechaHoraEvento>25-10-2019 12:34:56</fechaHoraEvento>
<fechaHoraRecepcion>25-10-2019 12:34:56</fechaHoraRecepcion>
<latitud>-22.215328</latitud>
<longitud>-49.6559497</longitud>
<altitud>666</altitud>
<velocidad>20</velocidad>
<rumbo>180</rumbo>
<codigo>0</codigo>
</movil>
</registro>
</tem:xmlSerializado>
</tem:ProcessXML>
</soapenv:Body>
</soapenv:Envelope>
`
当然,在请求有效负载中,我添加空格只是为了更清晰。如果您希望减小请求有效负载的大小,则可以毫无问题地删除它们。
[很久以前,我使用C#,但是我分析了代码的一部分,我说在ProcessXml方法中存储在参数xmlString中的值不是网络所期望的格式服务,因此应要求返回错误400。这也是我身上发生的事情。
我希望有帮助。