为wsHttpBinding配置WCF

时间:2013-08-07 21:05:37

标签: wcf wcf-binding wcf-security

我有一个使用basicHttpBinding的WCF服务,我正在尝试将其配置为通过https并使用SQL成员资格提供程序进行身份验证,为此我尝试将其转换为使用wsHttpBinding。

但是,使用更新的配置时,当我尝试连接客户端时出现以下错误:

  

无法在ServiceModel客户端配置部分中找到引用合同“KFileService.IKFileWcfService”的默认端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。

以下是服务器的web.config的相关部分:

<system.serviceModel>
    <protocolMapping>
      <remove scheme="http" />
      <add scheme="https" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_IKFileWcfServiceBinding" />
    </protocolMapping>
    <behaviors>
      <serviceBehaviors>
        <behavior name="KFileWcfServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483646" />
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
              membershipProviderName="SqlMembershipProvider" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="KFileWcfServiceBehavior" name="KFileWcfService">
        <endpoint address="https://localhost:36492/KFileWcfService.svc"
          binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_IKFileWcfServiceBinding"
          name="wsHttpBinding_IKFileWcfService" bindingName="wsHttpBinding_IKFileWcfServiceBinding"
          contract="KFileWcfService.IKFileWcfService">
          <identity>
            <certificateReference storeLocation="CurrentUser" />
          </identity>
        </endpoint>
      </service>
    </services>
    <serviceHostingEnvironment minFreeMemoryPercentageToActivateService="0" multipleSiteBindingsEnabled="true"/>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBinding_IKFileWcfServiceBinding" maxBufferPoolSize="2147483647"
          maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="32" maxStringContentLength="100000" maxArrayLength="2147483647"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="Message">
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
</system.serviceModel>

这是客户方:

  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBinding_IKFileWcfService" />
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://localhost:36492/KFileWcfService.svc"
        binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_IKFileWcfService"
        contract="KFileWcfService.IKFileWcfService" name="wsHttpBinding_IKFileWcfService" />
    </client>
  </system.serviceModel>

我已经尽力完成所有现有的问题和例子,但没有运气。谁能告诉我我做错了什么?

编辑:

进一步参考,这是与basicHttpBinding一起使用的服务器端配置:

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false 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="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483646" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="KFileWcfService">
        <endpoint address="https://localhost:36492/KFileWcfService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IKFileWcfService" contract="KFileService.IKFileWcfService" name="BasicHttpBinding_IKFileWcfService" />
      </service>
    </services>
    <serviceHostingEnvironment minFreeMemoryPercentageToActivateService="0" multipleSiteBindingsEnabled="true"/>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IKFileWcfService" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed">
          <readerQuotas maxDepth="32" maxStringContentLength="100000" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        </binding>
      </basicHttpBinding>
    </bindings>
</system.serviceModel>

客户:

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IKFileWcfService" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://localhost:36492/KFileWcfService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IKFileWcfService"
                contract="KFileService.IKFileWcfService" name="BasicHttpBinding_IKFileWcfService" />
        </client>
    </system.serviceModel>

1 个答案:

答案 0 :(得分:6)

您尝试使用的客户端上的服务合同类型,基于您的错误消息:

KFileService.IKFileWcfService

您在客户端配置上的服务合同接口的类型:

KFileWcfService.IKFileWcfService

他们应该是一样的。将客户端配置更改为

... contract="KFileService.IKFileWcfService" ...

它应该有用。