【问题标题】:Configuring WCF for wsHttpBinding为 wsHttpBinding 配置 WCF
【发布时间】:2013-08-09 10:41:35
【问题描述】:

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

【问题讨论】:

  • 或许可以向我们展示您较旧的 basicHttpBinding。
  • 将其添加到问题中。

标签: wcf wcf-binding wcf-security


【解决方案1】:

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

KFileService.IKFileWcfService

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

KFileWcfService.IKFileWcfService

它们应该是相同的。将客户端配置更改为

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

它应该可以工作。

【讨论】:

  • 好旧的stackoverflow。为拼写错误提供过肩支持。不错的皮卡。
  • 好的,谢谢!不知道在注意到自己之前我会盯着它多长时间。看起来配置仍然存在一些问题,但这确实解决了问题中提出的错误,因此我将其标记为已接受的答案。再次感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-08
  • 1970-01-01
  • 1970-01-01
  • 2011-09-23
  • 1970-01-01
  • 1970-01-01
  • 2017-04-03
相关资源
最近更新 更多