I recently had to make a service call to a WCF service from within a K2 blackpearl code event and didn’t have access to the configuration file to configure my binding and endpoint.  I created the client using the Svcutil.exe tool and then built a basic WSHttpBinding and EndpointAddress to call the constructor of my client so I could get to work and use it.

   1: //Build a basic WSHttpBinding object
   2: var myBinding = new System.ServiceModel.WSHttpBinding();
   3:  
   4: // Build the Services EndPoint.
   5: var myEndpointAddress = new System.ServiceModel.EndpointAddress(webserver + "/Services/MyWCFService.svc");
   6:  
   7: // Create a WCF Service Client instance.
   8: MyWCFServiceClient client = new MyWCFServiceClient(myBinding, myEndpointAddress);
   9:  

This worked for a little bit, however, it turned out my EndpointAddress was a little too simple when the application pool was changed by our administrator to run under a domain account’s credentials and I started receiving the error below.

System.ComponentModel.Win32Exception (0x80004005): Security Support Provider Interface (SSPI) authentication failed. The server may not be running in an account with identity ‘host/servername. If the server is running in a service account (Network Service for example), specify the account’s ServicePrincipalName as the identity in the EndpointAddress for the server. If the server is running in a user account, specify the account’s UserPrincipalName as the identity in the EndpointAddress for the server.

To fix the problem, I had to tweak how I created my so that I passed in a DNS identity of the local system.  The code below is the code that got things working again.

   1: //Build a basic WSHttpBinding object
   2: var myBinding = new System.ServiceModel.WSHttpBinding();
   3:  
   4: // Build the Services EndPoint.
   5: var myEndpointAdd = new EndpointAddress(new Uri(webserver + "/Services/MyWCFService.svc"),
   6:      EndpointIdentity.CreateDnsIdentity("localhost"));
   7:  
   8: // Create a WCF Service Client instance.
   9: MyWCFServiceClient client = new MyWCFServiceClient (myBinding, myEndpointAdd);