Reputation: 5670
I am trying to consume a WCF service in my console app. My App.Config file looks like this
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_InventItemGroupService" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://mydomain.com/MicrosoftDynamicsAXAif50/inventitemgroupservice.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_InventItemGroupService"
contract="ServiceReference1.InventItemGroupService" name="WSHttpBinding_InventItemGroupService">
<identity>
<userPrincipalName value="asd@as" />
</identity>
</endpoint>
</client>
</system.serviceModel>
Console app code to make authentication part.
protected ProgramClass(AifSos.InventItemGroupServiceClient inventItemGroupServiceClient) // Constructor
{
MInventItemGroupServiceClient = inventItemGroupServiceClient;
// ReSharper disable once PossibleNullReferenceException
MInventItemGroupServiceClient.ClientCredentials.Windows.ClientCredential.UserName = "un";
MInventItemGroupServiceClient.ClientCredentials.Windows.ClientCredential.Password = "pw";
MInventItemGroupServiceClient.ClientCredentials.Windows.ClientCredential.Domain = "domain";
}
All seems okay for me, But it always throws an error
The caller was not authenticated by the service.
Can any one point out what I am missing?
Upvotes: 0
Views: 363
Reputation: 7601
1 Go to your Client Project Properties.
a. Go to services tab
Enable this settings and use authentication mode windows
2 change app.config file inside client project with this two sample line
<security mode="None">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="false" algorithmSuite="Default" establishSecurityContext="false" />
</security>
3 change app.config file inside service project
<security mode="None">
<message clientCredentialType="Windows" negotiateServiceCredential="false" algorithmSuite="Default" establishSecurityContext="false" />
</security>
4 in client code when you creating service instance and calling for a service use this line to provide login info in service pc.
Service1Client client = new Service1Client();
client.ClientCredentials.Windows.ClientCredential.UserName = "ETLIT-1";
client.ClientCredentials.Windows.ClientCredential.Password = "etl";
client.ClientCredentials.Windows.AllowNtlm = false;
client.ClientCredentials.Windows.ClientCredential.Domain = "ETLIT-1-PC";
Console.WriteLine(client.addNumber(23, 2));
Upvotes: 1