我在IIS中的Windows 2016服务器上托管了WCF服务。我还有一个Windows应用程序来测试这个WCF服务。如果我在除托管WCF的服务器之外的任何机器中运行此Windows应用程序,服务工作正常。下面是我对WCF的配置。我无法弄清楚服务有什么问题。
<system.serviceModel>
<services>
<service behaviorConfiguration="TestBehavior" name="">
<endpoint address="" binding="wsHttpBinding" contract="" bindingConfiguration="TestSecConfig">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="TestSecConfig">
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="TestBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
我的问题与此问题中的描述完全相同,但解决方案无效。 the caller was not authenticated by the service -- when using host name in site and call locally
默认情况下,Wshttpbinding安全模式的凭据是Windows凭据,以下配置是等效的。
<bindings>
<wsHttpBinding>
<binding name="TestSecConfig">
</binding>
</wsHttpBinding>
</bindings>
<wsHttpBinding>
<binding>
<security mode="Message">
<message clientCredentialType="Windows"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
因此调用者应在调用此服务时指定Windows凭据。 Windows凭据是服务器Windows帐户(承载WCF服务的主机)。
ServiceReference2.Service1Client client = new ServiceReference2.Service1Client();
client.ClientCredentials.Windows.ClientCredential.UserName = "administrator";
client.ClientCredentials.Windows.ClientCredential.Password = "123456";
根据您的要求,您还可以指定clientCredentialType =“None”。 https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.wshttpbinding.security?view=netframework-4.8 https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.wshttpsecurity.message?view=netframework-4.8#System_ServiceModel_WSHttpSecurity_Message 如果有什么我可以帮忙,请随时告诉我。