1

我有一个 WCF 服务,它使用 https 进行通信,使用 json 作为响应格式。我不希望任何人都可以使用我的方法,因此我将 IIS 中的身份验证从匿名和基本更改为基本。

到目前为止,浏览器正在询问用户并通过,但我收到以下错误:

找不到与绑定 WebHttpBinding 的终结点的方案 http 匹配的基地址。注册的基地址方案是 [https]。

我必须对我的端点进行什么更改才能使用身份验证?

我的 web.config 看起来像:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="false" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="restBinding">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Basic" proxyCredentialType="Basic" />
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service name="ContactLibrarySecure.ContactLibraryService">
        <endpoint address="mex" binding="mexHttpsBinding" bindingConfiguration=""
          name="mex" contract="IMetadataExchange" />
        <endpoint address="rest" behaviorConfiguration="restBehavior"
          binding="webHttpBinding" bindingConfiguration="restBinding"
          name="rest" contract="ContactLibrarySecure.IContact" />
        <host>
          <baseAddresses>
            <add baseAddress="https://192.168.1.31/ContactLibrary2.0HTTPS" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="restBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>
4

1 回答 1

1
    <?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="false" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="soapBinding" maxBufferSize="2000000000" maxBufferPoolSize="2000000000"
          maxReceivedMessageSize="2000000000">
          <security mode="Transport">
            <transport clientCredentialType="Windows" proxyCredentialType="Basic" />
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </basicHttpBinding>
      <wsHttpBinding>
        <binding name="mexBinding">
          <security mode="Transport">
            <transport clientCredentialType="Windows" />
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
      <webHttpBinding>
        <binding name="restBinding" closeTimeout="00:10:00" sendTimeout="00:10:00"
          maxBufferSize="2000000000" maxBufferPoolSize="2000000000" maxReceivedMessageSize="2000000000">
          <security mode="Transport">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service name="ContactLibrarySecure.ContactLibraryService">
        <endpoint address="mex" binding="wsHttpBinding" bindingConfiguration="mexBinding"
          name="mex" contract="IMetadataExchange" />
        <endpoint address="rest" behaviorConfiguration="restBehavior"
          binding="webHttpBinding" bindingConfiguration="restBinding"
          name="rest" contract="ContactLibrarySecure.IContact" />
        <endpoint address="soap" behaviorConfiguration="soapBehavior"
          binding="basicHttpBinding" bindingConfiguration="soapBinding"
          name="soap" contract="ContactLibrarySecure.IContact" />
        <host>
          <baseAddresses>
            <add baseAddress="https://192.168.1.31/ContactLibrary2.0HTTPS" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="restBehavior">
          <webHttp />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
        <behavior name="soapBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

这个配置文件解决了我的问题。在 iis 中安装 windows 身份验证后,我从基本身份更改为 windows 身份验证。

于 2012-04-10T12:22:23.490 回答