首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >System.ServiceModel.Description.ServiceEndpoint.EndpointBehaviors对System.ServiceModel.Description.ServiceEndpoint.Behaviors

System.ServiceModel.Description.ServiceEndpoint.EndpointBehaviors对System.ServiceModel.Description.ServiceEndpoint.Behaviors
EN

Stack Overflow用户
提问于 2016-07-12 15:58:19
回答 1查看 906关注 0票数 0

这是一个处理.net框架内部的问题。在使用Java服务时,我必须更改端点行为,以添加自定义SOAP头( web服务需要一个nonce)和操作应答,以便WCF能够正确地反序列化响应。

在查看代码示例时,一个使用ServiceEndpoint.EndpointBehaviors,另一个使用ServiceEndpoint.Behaviors。经过一些测试,这两种属性似乎都有相同的影响,可以互换,这就引出了一个问题,这两者之间的区别是什么?

示例代码:

自定义端点行为:

代码语言:javascript
复制
public class ApplyClientEndpointBehaviour<T> : IEndpointBehavior where T : IClientMessageInspector
{
    public ApplyClientEndpointBehaviour(T item)
    {
        _item = item;
    }

    private readonly T _item;

    public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
    {
        clientRuntime.ClientMessageInspectors.Add(_item);
    }

   public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
    {
        // Nothing special here
    }

    public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
    {
        // Nothing special here
    }

    public void Validate(ServiceEndpoint endpoint)
    {
        // Nothing special here
    }
}

然后

代码语言:javascript
复制
var client = new <wcf client child class of System.ServiceModel.ClientBase generated through Add Service Reference>

client.Endpoint.EndpointBehaviors.Add(new ApplyClientEndpointBehaviour<SomeIClientMessageInspector>(new SomeIClientMessageInspector()));
client.Endpoint.Behaviors.Add(new ApplyClientEndpointBehaviour<AnotherIClientMessageInspector>(new AnotherIClientMessageInspector()));

SomeIClientMessageInspectorAnotherIClientMessageInspector分配给Endpoint.BehaviorsEndpoint.EndpointBehaviors将不会导致实际功能的更改。两者都可以互换性地分配给一个或另一个,而服务端点的行为没有变化。这就引出了这样的问题:如果这两个属性之间有什么不同,或者是添加了一个属性,而另一个属性是为了向后的可比性而被添加的呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-12 16:48:10

查看反编译的源代码,EndpointBehaviors只返回Behaviors集合。

代码语言:javascript
复制
[__DynamicallyInvokable]
public KeyedCollection<System.Type, IEndpointBehavior> EndpointBehaviors
{
  [__DynamicallyInvokable] get
  {
    return (KeyedCollection<System.Type, IEndpointBehavior>) this.Behaviors;
  }
}

EndpointBehaviors可以从.NET Framework4.5和便携平台中获得,而Behaviors从3.0起就可以使用了。我猜想这是桌面和便携平台的API合并的结果。

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

https://stackoverflow.com/questions/38333824

复制
相关文章

相似问题

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