【问题标题】:The CustomBinding on the ServiceEndpoint with contract 'IService1' lacks a TransportBindingElement error when trying to access wcf service尝试访问 wcf 服务时,带有合同“IService1”的 ServiceEndpoint 上的 CustomBinding 缺少 TransportBindingElement 错误
【发布时间】:2013-08-24 02:52:07
【问题描述】:

我正在尝试访问 WCF 服务。但它给了我以下错误:

ServiceEndpoint 上的 CustomBinding 与合同“IService1” 缺少 TransportBindingElement。每个绑定必须至少有一个 从 TransportBindingElement 派生的绑定元素。

描述:执行过程中发生了未处理的异常 当前的网络请求。请查看堆栈跟踪以获取更多信息 有关错误的信息以及它在代码中的来源。

异常详细信息:System.InvalidOperationException:CustomBinding 在具有合同“IService1”的 ServiceEndpoint 上缺少 传输绑定元素。每个绑定必须至少有一个绑定 派生自 TransportBindingElement 的元素。

以下是我的服务模型完整配置:

<system.serviceModel>
<!-- change -->
<bindings>
  <customBinding>
    <binding name="Wrabind" closeTimeout="00:02:00" openTimeout="00:02:00">
      <transactionFlow />
      <security authenticationMode="SecureConversation" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
        <localClientSettings maxClockSkew="00:07:00" />
        <localServiceSettings maxClockSkew="00:07:00" />
        <secureConversationBootstrap messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
          <localClientSettings maxClockSkew="00:30:00" />
          <localServiceSettings maxClockSkew="00:30:00" />
        </secureConversationBootstrap>
      </security>

      <textMessageEncoding />
      <httpTransport authenticationScheme="Anonymous" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" proxyAuthenticationScheme="Anonymous" realm="" useDefaultWebProxy="true" />
    </binding>
  </customBinding>
</bindings>
<!-- change -->
<services>
  <service behaviorConfiguration="WCFService.Service1Behavior"
      name="WCFService.Service1">
    <endpoint address="http://subdomain.domain.com/service1.svc" binding="customBinding"
        bindingName="Wrabind" contract="WCFService.IService1" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="WCFService.Service1Behavior">
      <!-- To avoid disclosing metadata information, set the value below to false before deployment -->
      <serviceMetadata httpGetEnabled="false" />
      <!-- change -->
      <!--<serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="WrangleCoreService.Authentication.DistributorValidator, WrangleCoreService"/>
        <serviceCertificate findValue="WCFService" storeLocation="LocalMachine" storeName="TrustedPeople" x509FindType="FindBySubjectName"/>
      </serviceCredentials>-->
      <!-- change -->
      <!-- 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="false" />

    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment>
  <baseAddressPrefixFilters>
    <add prefix="http://subdomain.domain.com/"/>
  </baseAddressPrefixFilters>
</serviceHostingEnvironment>
<!--<standardEndpoints>
  <webHttpEndpoint>
    <standardEndpoint name="" helpEnabled="true"
      automaticFormatSelectionEnabled="true"/>
  </webHttpEndpoint>
</standardEndpoints>-->

如您所见,它已经有了 Transport 元素。但我仍然在错误之上。是什么原因?

我的客户端配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>

    <bindings>
      <wsHttpBinding>
        <binding name="CustomBinding_IService1" />
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://subdomain.domain.com/service1.svc" binding="wsHttpBinding"
        bindingConfiguration="CustomBinding_IService1" contract="ServiceReference1.IService1"
        name="CustomBinding_IService1">
        <identity>
          <userPrincipalName value="DOMAIN\subdomaindomaincom_web" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>

【问题讨论】:

  • 请发布完整配置
  • @YaronNaveh 查看我更新的配置
  • 对我来说似乎不错,尝试进行一些任意更改(删除安全性,删除一些其他标签),看看是否某些标签有问题
  • 不应该是 bindingConfiguration="Wrabind",而不是 bindingName="Wrabind"
  • 同样去掉编码前的空格行

标签: c# .net wcf web-services custom-binding


【解决方案1】:

伙计,我建议你不要那样做。如果您在服务器上使用自定义绑定,您也应该在客户端中使用它。如果您在客户端使用 WSHttp,您的服务器应该具有相同的绑定端点。我怀疑您是否需要在您的情况下创建自定义绑定。在 90% 的情况下,标准的 WCF 绑定足以做出适当的解决方案。不要开发新的自行车。 至于您的第二个问题,假设它是在您的自定义绑定中使用 WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10 的原因,这需要出于安全目的使用证书。 无论如何,我建议您使用 WSHttp 更改自定义绑定

【讨论】:

  • 其实我遇到了stackoverflow.com/questions/18400608/…这个问题,所以我切换到customBinding
  • 哦,我知道在您的情况下,自定义绑定是一种方法。但是可以同步服务器和客户端上的时钟吗?您是否会像以前一样向安全异常状态发送消息?
  • 是的,它说明了同样的事情。时间同步也无济于事。由于安装我的应用程序的人可能比 MaxClockSkew 有更多的时差,因为我的应用程序将在全球范围内下载,所以这将限制他们使用我的应用程序。我不想要的。自两周以来,我一直在尝试找出解决方案。我现在没有选择了。请帮忙。
  • @AishwaryaShiva 很难模拟你的问题,所以我只能给你以下建议。确保您在服务器和客户端上具有相同的绑定配置。确保在客户端和服务器上都设置了 MaxClockSkew。确保在客户端设置 LocalClientSecuritySettings MaxClockSkew,在服务器端设置 LocalServiceSecuritySettings MaxClockSkew。如果您按照我所说的那样做所有事情-它应该可以工作。见msdn.microsoft.com/en-us/library/aa738468.aspx,希望对你有帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-01-07
  • 2013-10-14
  • 1970-01-01
  • 2014-02-19
  • 1970-01-01
  • 1970-01-01
  • 2020-12-01
相关资源
最近更新 更多