문제

I'm trying to build a C# SignalR app (console app on the server, winforms app on the client), and it works great (in Visual Studio) when both the client and server are on the same PC, but when I deploy the server and repoint the client to the server, I'm getting a "407 Proxy Authentication Required" exception when it tries to start.

This is my code...

        var _connection = new HubConnection("http://www.redacted.com:8088/");
        var _hub = _connection.CreateProxy("MyHub");
        _connection.Start().ContinueWith(task =>
        {
            if (task.IsFaulted)
                MessageBox.Show(string.Format("Could not connect - {0}", task.Exception.ToString()));
        }).Wait();

I noticed that HubConnection has a Credentials property, and so I figured I'd try replacating some code I've used with WebServices when dealing with proxies (shown below, where I just make an HTTP request out and then pick up the proxy settings and credentials from that), but I get the same exception.

        var _connection = new HubConnection("http://www.redacted.com:8088/");

        var req = (HttpWebRequest)WebRequest.Create("http://www.google.com");
        var proxy = new WebProxy(req.Proxy.GetProxy(req.RequestUri).AbsoluteUri) {UseDefaultCredentials = true};
        _connection.Credentials = proxy.Credentials;

        var _hub = _connection.CreateProxy("MyHub");
        _connection.Start().ContinueWith(task =>
        {
            if (task.IsFaulted)
                MessageBox.Show(string.Format("Could not connect - {0}", task.Exception.ToString()));
        }).Wait();

This is required for some work I'm doing for a client where they want their local PCs to be able to receive messages from a remote system that's hosted outside the company.

Thanks!

도움이 되었습니까?

해결책

Try to set the DefaultWebProxy:

WebProxy wproxy = new WebProxy("new proxy",true);
wproxy.Credentials = new NetworkCredential("user", "pass");
WebRequest.DefaultWebProxy = wproxy;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top