6

我有一个使用 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>
4

1 回答 1

6

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

KFileService.IKFileWcfService

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

KFileWcfService.IKFileWcfService

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

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

它应该工作。

于 2013-08-07T21:59:22.927 回答