我已经创建了WCF服务+客户端,并将该服务部署到另一台PC。服务正在运行。但是,当我通过Visual Studio在调试模式下执行客户端时,会出现错误:服务未对调用方进行身份验证。 PC,客户端和服务器都在同一本地网络上。
服务器端(服务)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<!-- This section is optional with the new configuration model
introduced in .NET Framework 4. -->
<service name="Digiteq.Services.LabSat.LabSatService"
behaviorConfiguration="LabSatServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/LabSat3/service"/>
</baseAddresses>
</host>
<!-- this endpoint is exposed at the base address provided by host: http://localhost:8733/LabSat/service -->
<endpoint address=""
binding="wsHttpBinding"
contract="Digiteq.Services.LabSat.ILabSat" />
<!-- the mex endpoint is exposed at http://localhost:8733/LabSat3/service/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="LabSatServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
客户端配置文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ILabSat" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://192.168.228.65:8000/LabSat3/service" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_ILabSat" contract="ILabSat"
name="WSHttpBinding_ILabSat">
<identity>
<servicePrincipalName value="host/MBO-NEW" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
答案 0 :(得分:0)
我认为问题可能是由客户端凭据引起的。 据我所知,wsHttpBinding的传输安全模式默认情况下为Message,而当我们将传输安全性设置为message时,客户端凭据类型默认为Windows。因此,我们需要明确提供可以由服务器端进行身份验证的凭据。
client.ClientCredentials.Windows.ClientCredential.UserName = "username";
client.ClientCredentials.Windows.ClientCredential.Password = "password";
这是正式文件。 official document
还可能需要识别服务器端,然后客户端需要手动指定终结点身份。这取决于您的配置和托管环境。 official document