Webservice连接被取消
本文关键字:取消 连接 Webservice | 更新日期: 2023-09-27 18:04:58
我有一个运行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只是再次尝试,然后第二个请求工作。
所以我想我的问题是:
- 有人见过这样的行为吗?你是怎么克服的?
- 我的问题是否可能与我看到的SoapUI的身份验证问题有关?
- 如何调试这样的问题?
解决方案是重新生成客户端的web服务代码。我们之前使用MS的Wsdl.exe工具生成代码;在Visual Studio (Add/Service Reference)内部重新生成后,生成的代码(似乎使用了较新的WS框架)工作得更好。我们很少看到问题中提到的错误