将 WCF 安全设置为 windows 身份验证

set WCF security to windows authentication

我在那里创建了一个空的 Web 应用程序并添加了 WCF 服务。使用以下教程

https://www.guru99.com/restful-web-services.html

在这里,我得到了其中包含 WCF 的应用程序。然后我创建了我的 WCF,它可以从浏览器访问,它以 json 格式返回数据。我真的很想拥有。但是我不希望它成为 public 我想要其中的基本身份验证。在我的 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

的某个地方

Then I created my WCF and it is accessible from browser and it is returning data in json format

这种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 身份验证。

如果问题仍然存在,请随时告诉我。