我希望客户端(它是一个 asp.net 站点)调用 wcf。两者都托管在我笔记本电脑的 IIS7 中。对于 WCF,我在 IIS7 中启用了基本身份验证并禁用了所有其他功能。对于客户端,我启用了基本身份验证并禁用了身份验证中的所有其他选项。
问题在于,使用下面的这些配置,客户端无法从 wcf 获取任何数据。
如果我在浏览器中通过向服务提供 url 导航到服务,那么我必须在弹出的表单中输入用户名/密码。
我要做的是通过用户名和密码保护我的 wcf,以便任何想要调用我的 wcf 的人都必须提供用户名/密码,并且我的 wcf 代码检查是否存在(例如在 AD 中)并进行相应的身份验证.
我的客户端(调用 WCF 的简单 ASP.net 网站)web.config:
<configuration>
<appSettings>
<add key="userName" value="Administrator"/>
<add key="password" value="pass"/>
<!--<add key="url" value="http://localhost:57895/ListData.svc"/>-->
<!--http://localhost/WCF/-->
<add key="url" value="http://localhost:8082/ListData.svc"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
我的 WCF 服务 web.config:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="Logging" value="true"/>
</appSettings>
<connectionStrings/>
<system.web>
<authentication mode="Windows"></authentication>
<compilation debug="true" />
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="httpBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpBinding>
<!--<webHttpBinding>
<binding name="webHttpTransportSecurity">
<security mode="Transport">
<transport clientCredentialType="Basic"/>
</security>
</binding>
</webHttpBinding>-->
</bindings>
<services>
<service behaviorConfiguration="SecureRESTSvcTestBehavior" name="Hdir.ListData">
<!--<host>
<baseAddresses>
<add baseAddress="http://localhost:57895/ListData/"/>
</baseAddresses>
</host>-->
<!--webHttpBinding allows exposing service methods in a RESTful manner-->
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="httpBinding" behaviorConfiguration="webHttpBehavior" contract="Hdir.IListData"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<!--<behavior name=" ">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>-->
<behavior name="SecureRESTSvcTestBehavior">
<!-- To avoid disclosing metadata information, set the value below to
false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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="false"/>
<serviceAuthorization serviceAuthorizationManagerType="Hdir.CustomAuthorizationManager, Hdir"/>
<!--<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Hdir.Hp.Data.CustomUserNameValidator, Hdir.Hp.Data" />
</serviceCredentials>-->
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<!--<webHttp/>-->
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<directoryBrowse enabled="true"/>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*"/>
<add name="Access-Control-Allow-Headers" value="x-requested-with"/>
<add name="Access-Control-Request-Method" value="GET"/>
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>