2
我有一个运行SAP系统的客户端,我的任务是通过Web服务将我们的系统连接到SAP系统。客户端提供了WSDL文件,我从中生成了相应的C#代码,我将按如下方式调用:Webservice连接被取消
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中看到的身份验证问题有关吗?
- 如何调试这样的问题?
当你得到'HTTP/1.1 401 Unauthorized'时,入站响应头中没有'challange header'? –
当使用SoapUI是正确的时候,初始'401'是正确的 - 这就是http基本认证的工作方式。客户端不知道需要身份验证,因此它在不提供用户名/密码的情况下执行'POST',服务器用'401'做出响应,然后客户端再次尝试,这次提供用户名/密码并且'POST'成功。您可以通过勾选* Pre-emptive auth *复选框来阻止它在SoapUI中的使用。 – mjturner
@mjturner:谢谢你的解释。你认为这可能与我的一般问题有关吗?我注意到服务对象有一个名为PreAuthenticate的布尔标志,它可能和你提到的SoapUI选项一样... – csoltenborn