WCF:如何将自定义 ServiceBehavior 添加到 WCF 配置中
您好,我有自己的 ServiceBehavior:
public class StructureMapServiceBehavior : IServiceBehavior
{
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers)
{
ChannelDispatcher cd = cdb as ChannelDispatcher;
if (cd != null)
{
foreach (EndpointDispatcher ed in cd.Endpoints)
{
ed.DispatchRuntime.InstanceProvider =
new StructureMapInstanceProvider(serviceDescription.ServiceType);
}
}
}
}
public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
{
}
public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
}
}
如何使用 WCF 配置工具将其添加到 App.config 中?
:
Hi I have my own ServiceBehavior:
public class StructureMapServiceBehavior : IServiceBehavior
{
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers)
{
ChannelDispatcher cd = cdb as ChannelDispatcher;
if (cd != null)
{
foreach (EndpointDispatcher ed in cd.Endpoints)
{
ed.DispatchRuntime.InstanceProvider =
new StructureMapInstanceProvider(serviceDescription.ServiceType);
}
}
}
}
public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
{
}
public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
}
}
How i can add it in App.config with WCF configuration tool ?
:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个继承自
BehaviorExtensionElement
的类:然后在配置文件中注册您的扩展:
完成后,您可以像使用其他扩展一样使用您的扩展。
编辑:使用配置工具来完成它,它是类似的。创建上述类后,在 WCF 配置工具的扩展部分中注册您的行为(高级 -> 扩展 -> 行为元素扩展)
Create a class that inherit from
BehaviorExtensionElement
:Then register your extension in the config file:
When that is done you can use your extension like any other.
EDIT: To do it using the configuration tool, it is similar. Once the class above is created, register your behavior in the extensions section of the WCF configuration tool (advanced->extensions->behavior element extensions)
您必须创建从
BehaviorExtensionElement
派生的自定义类,它将负责创建您的自定义行为。 这是示例 以及在配置文件中添加此类行为所需的步骤(必须首先在behaviorsExtensions
中注册扩展 部分)。在配置工具中,我想您首先必须在“高级”>“中”注册扩展。扩展,之后您可能将能够使用该服务行为。
You have to create custom class derived from
BehaviorExtensionElement
which will be responsible for creating your custom behavior. Here is the example with steps needed to add such behavior in configuration file (extension must be registered first inbehaviorsExtensions
section).In configuration tool I guess you will first have to register the extension in Advanced > Extensions and after that you will probably will be able to use that service behavior.