Thursday, September 8, 2011

WCF Callbacks related - Steps to do on client-side when using wsDualHttpBinding


Client = WPF app (chat application)
WCF Service = uses wsDualHttpBinding (to make callbacks to the clients)
OS= Windows XP
(The whole project is an implementation of  - http://www.eggheadcafe.com/tutorials/aspnet/b5ada8df-58c5-492f-b368-457b3a4f137c/notify-client-applications-using-wcf-callbacks.aspx )

After initially developing the client (a WPF app) and the WCF Service on the same machine, we moved the WCF Service to a test server.

I received the error message - The caller was not authenticated by the service..

Upon googling, it turned out that this is the common error message that is received when developers typically move their WCF Service to another machine.

1. In client's app.config file :

<security mode="None">
                        <message clientCredentialType="None" negotiateServiceCredential="false" />
                    </security>


2. Specified "clientBaseAddress" attribute for "binding" element in client's app.config:

clientBaseAddress="http://system2:8001/TempUri/"

(I used machine-name or IP address instead of "localhost" in clientBaseAddress)

3. Add 8001 port to Firewall's Exception list

Did the following to make the WPF app, running as a non-admin , to receive the callback properly from the WCF service. This will take care of the following error -
HTTP could not register URL http://*:8001/TempUri/. Your process does not have access rights to this namespace


4. Download HttpNamespaceManager tool from http://blogs.msdn.com/b/paulwh/archive/2007/05/04/addressaccessdeniedexception-http-could-not-register-url-http-8080.aspx
HttpNamespaceManager.zip

5. Add SDDL using HttpNamespaceManager tool - Add Users group AND give rights to Users group

6. (OPTIONAL step) Specifying clientBaseAddress via code instead of from app.config - If we do this, we do not have to change app.config when we install the app on the user's machine

// modify ClientBaseAddress to have this machine's IP address in the Url
// The ClientBaseAddress is needed for the Service to contact the client

WSDualHttpBinding w = (WSDualHttpBinding)this.chatServiceClient.Endpoint.Binding;

w.ClientBaseAddress = new Uri("http://" + getIPAddress() + ":8001/TempUri");      

chatServiceClient.Endpoint.Binding = w;

........
........
........

private string getIPAddress()
{
string myClientMachineName = System.Net.Dns.GetHostName();
        IPHostEntry myClientMachineAddressList = System.Net.Dns.GetHostEntry(myClientMachineName);
        return myClientMachineAddressList.AddressList[0].ToString();
}

No comments:

Post a Comment

Followers

Blog Archive