Web服务连接已取消

时间:2015-07-28 09:09:36

标签: c# web-services sap

我有一个运行SAP系统的客户,我的任务是通过Web服务将我们的系统与该SAP系统连接。客户端提供了WSDL文件,我从中生成了相应的C#代码,我调用如下:

Service service = new Service();
service.Url = "myUrl";
service.Credentials = new NetworkCredential("user", "pw");
ServiceResponse result = new ServiceResponse();
try
{
    result = service.MyOperation(myData);
    Console.WriteLine("Result.EfReturn {1}, Result.EtMess[0].Message {2}", result.EvReturn, result.EtMess[0].Message);
}
catch (System.Exception ex)
{
    Console.WriteLine("Exception:\n" + ex.ToString());
}

这一般起作用。然而,每隔一段时间(比如:每200个请求左右,有时更频繁)我得到一个例外:

System.Net.WebException: Die Anfrage wurde abgebrochen: Die Anfrage wurde abgebrochen..
   bei System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
   bei System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
   bei System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   bei WebServices.WebService_SAP.service.MyOperation(MyData myData) in c:\Users\cso\Desktop\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1\ServiceTest.cs:Zeile 54.

奇怪的是,使用SoapUI时不会发生这种情况,但我会为每一个请求获取身份验证错误(但这似乎不会影响结果) - 日志输出如下所示:

Wed Jul 22 11:19:18 CEST 2015:DEBUG:Connection can be kept alive indefinitely
Wed Jul 22 11:19:18 CEST 2015:DEBUG:Stale connection check
Wed Jul 22 11:19:18 CEST 2015:DEBUG:Attempt 1 to execute request
Wed Jul 22 11:19:18 CEST 2015:DEBUG:Sending request: POST /some/service/binding HTTP/1.1
Wed Jul 22 11:19:18 CEST 2015:DEBUG:Receiving response: HTTP/1.1 401 Unauthorized
Wed Jul 22 11:19:18 CEST 2015:DEBUG:Connection can be kept alive indefinitely
Wed Jul 22 11:19:18 CEST 2015:DEBUG:Target requested authentication
Wed Jul 22 11:19:18 CEST 2015:DEBUG:Authorization challenge processed
Wed Jul 22 11:19:18 CEST 2015:DEBUG:Authentication scope: BASIC 'SAP NetWeaver Application Server [TSE/881]'@somedomain:8033
Wed Jul 22 11:19:18 CEST 2015:INFO:somedomain:8033 requires authentication with the realm 'SAP NetWeaver Application Server [TSE/881]'
Wed Jul 22 11:19:18 CEST 2015:DEBUG:Found credentials
Wed Jul 22 11:19:18 CEST 2015:DEBUG:Attempt 2 to execute request
Wed Jul 22 11:19:18 CEST 2015:DEBUG:Sending request: POST /some/service/binding HTTP/1.1
Wed Jul 22 11:19:19 CEST 2015:DEBUG:Receiving response: HTTP/1.1 200 OK

对我来说,看起来SoapUI只是再次尝试,然后第二个请求就可以了。

所以我想我的问题是:

  1. 有人见过这种行为吗?你是怎么克服它的?
  2. 我的问题可能与我在SoapUI中看到的身份验证问题有关吗?
  3. 如何调试此类问题?

1 个答案:

答案 0 :(得分:0)

解决方案是重新生成客户端的Web服务代码。我们之前使用MS的Wsdl.exe工具生成了代码;从Visual Studio内部重新生成(添加/服务引用)后,生成的代码(似乎使用较新的WS框架)工作得更好。我们很少看到问题中提到的错误。

相关问题