jeudi 15 mai 2014

c# - consommer un Webservice - débordement de pile


    try
{
string xml = XMLExporter.OrderToXML(order);

WebRequest request = WebRequest.Create("http://localhost:60159/intranet/webservice/OrderService.asmx/ReceiveOrder");
request.Method = "POST";

byte[] byteArray = Encoding.UTF8.GetBytes(xml);

request.ContentType = "application/xml";
request.ContentLength = byteArray.Length;

Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();

WebResponse webResponse = request.GetResponse(); // ERROR HERE
}
catch // 500 error
{
return false;
}
return true;

Web.Config:


  <system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ReceiveOrder" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:60159/intranet/webservice/OrderService.asmx" binding="basicHttpBinding" bindingConfiguration="ReceiveOrder" contract="OrderService.ReceiveOrder" name="ReceiveOrder" />
</client>


<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>

"The remote server returned an error: (500) Internal Server Error."


when i call the method directly from the code it works fine!


Can anyone shed a light on this error?




If you get à http error 500 it means that it's the server part that throw so you should have a look inside the method ReceiveOrder in OrderService.asmx.


To resume it's not a problem from the caller, but from the receiver.



    try
{
string xml = XMLExporter.OrderToXML(order);

WebRequest request = WebRequest.Create("http://localhost:60159/intranet/webservice/OrderService.asmx/ReceiveOrder");
request.Method = "POST";

byte[] byteArray = Encoding.UTF8.GetBytes(xml);

request.ContentType = "application/xml";
request.ContentLength = byteArray.Length;

Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();

WebResponse webResponse = request.GetResponse(); // ERROR HERE
}
catch // 500 error
{
return false;
}
return true;

Web.Config:


  <system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ReceiveOrder" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:60159/intranet/webservice/OrderService.asmx" binding="basicHttpBinding" bindingConfiguration="ReceiveOrder" contract="OrderService.ReceiveOrder" name="ReceiveOrder" />
</client>


<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>

"The remote server returned an error: (500) Internal Server Error."


when i call the method directly from the code it works fine!


Can anyone shed a light on this error?



If you get à http error 500 it means that it's the server part that throw so you should have a look inside the method ReceiveOrder in OrderService.asmx.


To resume it's not a problem from the caller, but from the receiver.


0 commentaires:

Enregistrer un commentaire