首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为wsHttpBinding配置WCF

为wsHttpBinding配置WCF
EN

Stack Overflow用户
提问于 2013-08-07 21:05:37
回答 1查看 13.6K关注 0票数 6

我有一个使用basicHttpBinding工作的WCF服务,我试图将它配置为检查https并使用一个SQL成员资格提供程序进行身份验证,为了做到这一点,我试图将它转换为使用wsHttpBinding。

但是,使用更新的配置,当我试图连接到客户端时,我会得到以下错误:

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

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

代码语言:javascript
复制
<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>

这里是客户端:

代码语言:javascript
复制
  <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一起工作的服务器端配置:

代码语言:javascript
复制
  <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>

和客户:

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-07 21:59:22

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

代码语言:javascript
复制
KFileService.IKFileWcfService

在客户端配置中具有的服务契约接口的类型:

代码语言:javascript
复制
KFileWcfService.IKFileWcfService

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

代码语言:javascript
复制
... contract="KFileService.IKFileWcfService" ...

而且它应该能工作。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18113821

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档