WCF-1服务,多个端点和多个行为?

时间:2014-09-10 11:43:00

标签: wcf wcf-binding

我有1个服务和多个端点,如下所示。我希望有一个普遍的行为并用另一种行为覆盖我的wshttpbinding但是当我尝试我收到错误告诉我

分析程序错误消息:没有名为' CredentialValidator'的终结点行为。

我做错了什么?

 <services>
  <service name="myservice.Service.myserviceService" behaviorConfiguration="myserviceBehaviour">
    <host>
      <baseAddresses>
        <add baseAddress="https://localhost:44300/myService.svc"/>
        <!--<add baseAddress="http://localhost:54941/myService.svc"/>-->
        <!--<add baseAddress="http://myservicewcf.myurl-staging.com/myService.svc"/>-->
        <add baseAddress="https://myservice.myurl-staging.com/myService.svc"/>
        <add baseAddress="https://myservice.production.com/myService.svc"/>
        <!--<add baseAddress="https://myservicetest.myurl-staging.com/myService.svc"/>-->
      </baseAddresses>
    </host>
    <endpoint name="myserviceSoap12Endpoint" address="soap12" binding="customBinding"  bindingConfiguration="soap12selfBinding" contract="myservice.Service.ImyserviceService" behaviorConfiguration="CredentialValidator" />
    <endpoint name="myserviceWSHttpEndpoint" address="ws" binding="wsHttpBinding" bindingConfiguration="myserviceWSHttpBinding" contract="myservice.Service.ImyserviceService"/>
    <endpoint name="myserviceBasicHttpEndpoint" address="" binding="basicHttpBinding" bindingConfiguration="myserviceBasicHttpBinding" contract="myservice.Service.ImyserviceService"/>
    <!--<endpoint name="myserviceBasicHttpEndpoint2" address="" binding="basicHttpBinding" bindingConfiguration="myserviceBasicHttpBinding" contract="myservice.Service.ImyserviceService2"/>-->
    <endpoint name="myserviceMexEndpointHttps" address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name ="CredentialValidator">
      <serviceMetadata httpsGetEnabled="true"/>
      <serviceDebug
         includeExceptionDetailInFaults="true"/>
      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom"
                                customUserNamePasswordValidatorType="myservice.Service.CustomUserNameValidator, myservice"/>           
      </serviceCredentials>
    </behavior>
    <behavior name="myserviceBehaviour">
      <useRequestHeadersForMetadataAddress/>
      <serviceMetadata httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

1 个答案:

答案 0 :(得分:1)

尝试将CredentialValidator行为放在<endpointBehaviors>标记中,而不是<serviceBehaviors>

因为异常消息明确指出没有任何endpointBehavior具有该名称。所以给它一个!像这样:

<behaviors>
  **<endpointBehaviors>**
    <behavior name ="CredentialValidator">
      <serviceMetadata httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/> 
    </behavior>
  **</endpointBehaviors>**

  <serviceBehaviors>
    <behavior name="myserviceBehaviour">
      <useRequestHeadersForMetadataAddress/>
      <serviceMetadata httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>