我在其中添加了WCF服务的地方创建了一个空的Web应用程序。使用以下教程
https://www.guru99.com/restful-web-services.html
在这里,我获得了带有WCF的应用程序。然后,我创建了WCF,可以从浏览器访问它,并且以json格式返回数据。我真的很想拥有。但是我不希望它是公共的,我想要在其中进行基本身份验证。在我的web.conf中,有以下内容
<endpointBehaviors>
<behavior name="MyProject">
<webHttp />
</behavior>
</endpointBehaviors>
我尝试将其替换为
<webHttpBinding>
<binding name="IncreasedTimeout">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</webHttpBinding>
但这对我不起作用。我只想要clientCredentialType =“ Windows”在Web.Config中的某个位置
答案 0 :(得分:1)
然后我创建了WCF,可以从浏览器访问它, 返回json格式的数据
这种WCF服务应通过WebHttpbinding创建。因此,我们应该对这种类型的绑定应用基本身份验证。 请参考以下配置。
<system.serviceModel>
<services>
<service name="WcfService1.Service1">
<endpoint address="" binding="webHttpBinding" contract="WcfService1.IService1" bindingConfiguration="mybinding"></endpoint>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="mybinding">
<security mode="Transport">
<transport clientCredentialType="Basic"></transport>
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior>
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
我们还要注意的另一件事是,在使用基本身份验证托管WCF服务时,应在IIS身份验证模块中禁用Windows身份验证。
随时让我知道问题是否仍然存在。