views:

203

answers:

1

I have created a WCF client using channel factory. But I am not able to connect to a server in another machine. I am getting a (407) Prxy Authentication Required exception.

WSHttpBinding wsBinding = new WSHttpBinding();
        wsBinding.BypassProxyOnLocal = true;

        EndpointAddress endpoint =
          new EndpointAddress("http://machineName:7676/MyWCFService");
        ChannelFactory<IService> sericeInterface =
            new ChannelFactory<IService>(wsBinding, endpoint);

        sericeInterface.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
        sericeInterface = sericeInterface.CreateChannel();

This is my client connection code nippet. I am getting exception when I call a method of the service.

+1  A: 

Take a look at this CodePlex link, try to find a scenario that matches closely to yours. It provides checklists and samples of how to set the various credentials for different situations/bindings.

Also this MSDN link might help with Windows Authentication, which you seem to be using.

To assign credentials you'll need something like the below taken from the MSDN link:

CalculatorClient cc = new 
    CalculatorClient("WSHttpBinding_ICalculator");
// This code returns the WindowsClientCredential type.            
cc.ClientCredentials.Windows.ClientCredential.UserName = GetUserName();
cc.ClientCredentials.Windows.ClientCredential.Password = GetPassword();
Tanner