我有一个WCF服务,使用basichttpbinding和windows身份验证(没有匿名),
WCF服务托管在域服务器中 我需要从域外服务器使用该服务,该服务器不加入域,即工作组。那可能吗?请帮助您填写代码段。
如下配置
<bindings>
<basicHttpBinding>
<binding name="defaultBinding" receiveTimeout="01:00:00" sendTimeout="01:00:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="defaultServiceBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="defaultServiceBehavior" name="namespace.MyService">
<endpoint binding="basicHttpBinding" bindingConfiguration="defaultBinding" contract="namespace.IMyService">
<identity>
<dns value="abc.xyz.com"/>
</identity>
</endpoint>
</service>
</services>
编辑:这是我的客户代码
_securityServiceClient = new SecurityServiceClient();
_securityServiceClient.ClientCredentials.UserName.UserName = "lto3";
_securityServiceClient.ClientCredentials.UserName.Password = "Lydowe@1982";
我收到了这个错误
mscorlib.dll中发生了'System.ServiceModel.Security.MessageSecurityException'类型的异常,但未在用户代码中处理
其他信息:HTTP请求未经授权与客户端 认证方案'基本'。收到的身份验证标头 服务器是'Negotiate,NTLM'。
答案 0 :(得分:0)
尝试使用:
_securityServiceClient.ClientCredentials.Windows.ClientCredential =
new NetworkCredential("lto3", "Ludowe@1982");
根据msdn documentation ClientCredentials.Windows指定使用Windows身份验证时要使用的凭据。