-2
    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;

网络配置:

  <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>

“远程服务器返回错误:(500)内部服务器错误。”

当我直接从代码中调用该方法时,它工作正常!

任何人都可以阐明这个错误吗?

4

1 回答 1

1

如果你得到一个 http 错误 500,这意味着它是服务器部分抛出的,所以你应该看看 OrderService.asmx 中的 ReceiveOrder 方法。

恢复不是呼叫者的问题,而是接收者的问题。

于 2013-08-09T12:37:18.317 回答