question

Upvotes
Accepted
3 0 1 1

ClientApp.sln: proxy authentication

I'm trying to use the ClientApp.sln project, but I've some problem with the proxy authentication and I dont' find any documentation about it: can you help me? I would like to know how i can set proxy server, username and password. Thanks in advance

datastream-apidsws-apiproxy
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvote
Accepted
78.8k 250 52 74

@angelo.palumbo

I found a solution on stack overflow.

void SetProxySettings<TChannel>(ClientBase<TChannel> client, 
    bool useProxy, string address, int port, string login, string password) 
    where TChannel : class
{
    if (!useProxy) return;
    var b = client.Endpoint.Binding as BasicHttpBinding;
    if (b == null)
    {
        System.Diagnostics.Debug.WriteLine("Binding of this endpoint is not BasicHttpBinding");
        return;
    }
    b.ProxyAddress = new Uri(string.Format("http://{0}:{1}", address, port));
    b.UseDefaultWebProxy = false; // !!!
    b.Security.Mode = BasicHttpSecurityMode.Transport;
    b.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; // !!!
    b.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic; // !!!
    if (client.ClientCredentials == null) return;
    client.ClientCredentials.UserName.UserName = login;
    client.ClientCredentials.UserName.Password = password;
}

For example:

 using (var dsClient = new DSServiceClient())
            {
                // Issue a call to get the token
                SetProxySettings(dsClient, true, "127.0.0.1", 8080, "admin", "password");
...
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thanks for your solution. In configuration.svcinfo file there are some keys about proxy argument, I thought there was a directly callable method.

Upvote
24.6k 54 17 14

Hello @angelo.palumbo

The problem seems be be how to configure the proxy in Visual Studio application to run DataStream ClientApp demo and connects to DataStream Web Service from your company network.

I strongly suggest you contact your IT Network team to help you on setting proxy . You can find more detail regarding how to configure the proxy in Visual Studio from this post.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.