我有一个运行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再试一次,然后第二个请求起作用。
所以我想我的问题是:
发布于 2015-10-21 05:39:22
解决方案是重新生成客户端的webservice代码。在使用MS的Wsdl.exe工具生成代码之前,在Visual内部重新生成之后(添加/服务引用),生成的代码(它似乎使用的是更新的WS框架)工作得更好。我们很少看到像问题中提到的错误。
https://stackoverflow.com/questions/31671941
复制相似问题