C# Webservice 异步回调未因 HTTP 407 错误而被调用

发布于 2024-08-31 06:18:16 字数 1470 浏览 4 评论 0原文

我正在尝试测试拥有带有登录凭据的代理的客户的用例,尝试从我们的客户端使用我们的网络服务。

如果请求是同步的,我的工作就很简单。捕获 WebException,检查 407 代码,并提示用户输入登录凭据。

但是,对于异步请求,我似乎遇到了一个问题:回调永远不会被调用!我运行了wireshark跟踪,确实看到HTTP 407错误被传回,所以我很困惑该怎么办。

下面是设置回调并启动请求的代码:

TravelService.TravelServiceImplService svc = new TravelService.TravelServiceImplService();
svc.Url = svcUrl;
svc.CreateEventCompleted += CbkCreateEventCompleted;
svc.CreateEventAsync(crReq, req);

以及我使用 WSDL 时生成的代码:

public void CreateEventAsync(TravelServiceCreateEventRequest CreateEventRequest, object userState) {
        if ((this.CreateEventOperationCompleted == null)) {
            this.CreateEventOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCreateEventOperationCompleted);
        }

        this.InvokeAsync("CreateEvent", new object[] {
                    CreateEventRequest}, this.CreateEventOperationCompleted, userState);
    }

    private void OnCreateEventOperationCompleted(object arg) {
        if ((this.CreateEventCompleted != null)) {
            System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
            this.CreateEventCompleted(this, new CreateEventCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
        }
    }

调试 WS 代码,我发现即使是 SoapHttpClientProtocol.InvokeAsync 方法也没有调用其回调。我是否缺少某种配置?

I am trying to test the use-case of a customer having a proxy with login credentials, trying to use our webservice from our client.

If the request is synchronous, my job is easy. Catch the WebException, check for the 407 code, and prompt the user for the login credentials.

However, for async requests, I seem to be running into a problem: the callback is never getting called! I ran a wireshark trace and did indeed see that the HTTP 407 error was being passed back, so I am bewildered as to what to do.

Here is the code that sets up the callback and starts the request:

TravelService.TravelServiceImplService svc = new TravelService.TravelServiceImplService();
svc.Url = svcUrl;
svc.CreateEventCompleted += CbkCreateEventCompleted;
svc.CreateEventAsync(crReq, req);

And the code that was generated when I consumed the WSDL:

public void CreateEventAsync(TravelServiceCreateEventRequest CreateEventRequest, object userState) {
        if ((this.CreateEventOperationCompleted == null)) {
            this.CreateEventOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCreateEventOperationCompleted);
        }

        this.InvokeAsync("CreateEvent", new object[] {
                    CreateEventRequest}, this.CreateEventOperationCompleted, userState);
    }

    private void OnCreateEventOperationCompleted(object arg) {
        if ((this.CreateEventCompleted != null)) {
            System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
            this.CreateEventCompleted(this, new CreateEventCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
        }
    }

Debugging the WS code, I found that even the SoapHttpClientProtocol.InvokeAsync method was not calling its callback as well. Am I missing some sort of configuration?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅浅淡淡 2024-09-07 06:18:16

后来我发现问题出在我的代理服务器上,而不是代码上。切换到不同的代理服务器,并且不使用基本身份验证进行测试(无论如何谁使用它?),我能够得到我的回调。

I later found out that the problem was with my proxy server, and not the code. Switching to a different proxy server, as well as NOT testing with basic auth (who uses it anyway?), I was able to get my callbacks.

━╋う一瞬間旳綻放 2024-09-07 06:18:16

我有同样的问题。现在我只是实例化一个计时器并进入其中的断开连接状态。

I had the same issue. Now I just instantiate a timer and go to my disconnected state in there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文