我正在尝试在我的控制台应用中使用WCF服务。 我的App.Config文件看起来像这样
<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>
用于进行身份验证的控制台应用代码。
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";
}
对我来说一切似乎都没问题,但它总是会抛出错误
The caller was not authenticated by the service.
任何人都可以指出我缺少的东西吗?
答案 0 :(得分:1)
1转到您的客户项目属性。
一个。转到服务标签
启用此设置并使用身份验证模式窗口
2使用这两个示例行
更改客户端项目中的app.config文件 <security mode="None">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="false" algorithmSuite="Default" establishSecurityContext="false" />
</security>
3更改服务项目中的app.config文件
<security mode="None">
<message clientCredentialType="Windows" negotiateServiceCredential="false" algorithmSuite="Default" establishSecurityContext="false" />
</security>
创建服务实例并调用服务时,客户端代码中的4使用此行在服务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));