如何将自定义服务行为添加到WCF配置中
在Uri模板参数中有一个带有ComplexType的服务,我将CanConvert()和ConvertStringToValue()方法重写为MyQueryStringConverter类 我需要将该行为添加到web.config文件中 这就是行为如何将自定义服务行为添加到WCF配置中,wcf,Wcf,在Uri模板参数中有一个带有ComplexType的服务,我将CanConvert()和ConvertStringToValue()方法重写为MyQueryStringConverter类 我需要将该行为添加到web.config文件中 这就是行为 public class MyWebHttpBehavior : WebHttpBehavior { protected override QueryStringConverter GetQueryStringConverte
public class MyWebHttpBehavior : WebHttpBehavior
{
protected override QueryStringConverter GetQueryStringConverter(OperationDescription operationDescription)
{
return new MyQueryStringConverter();
}
}
以下是配置文件:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttp"
maxReceivedMessageSize="20000000" >
<security mode="None">
<transport clientCredentialType = "None"/>
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<add scheme="http" port="80" />
</defaultPorts>
</useRequestHeadersForMetadataAddress>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="Service.Service1" behaviorConfiguration="mexBehaviour">
<endpoint address="" binding="webHttpBinding" contract="Service.IService1" bindingConfiguration="webHttp" behaviorConfiguration="web"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
</endpoint>
</service>
</services>
</system.serviceModel>
请帮助添加该行为。首先,您必须使用配置文件中的behaviorExtensions元素注册您的行为:
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="MyWebHttpBehavior"
type="FullNameSpace.MyWebHttpBehavior, MyWebHttpBehavior.AssemblyName, Version=1.0.0.0, Culture=neutral" />
</behaviorExtensions>
</extensions>
希望有帮助。获取错误无法加载为扩展名“MyWebHttpBehavior”注册的类型“Service.MyWebHttpBehavior,Service,Version=1.0.0,Culture=neutral”@您必须确保命名空间和程序集名称正确,并且程序集位于服务二进制文件的同一文件夹(例如bin文件夹)中。是,所有内容都正确。命名空间和程序集名称相同@Ricardo Pontual只需检查程序集是否位于服务二进制文件的同一文件夹中,可能是bin文件夹。MyWebHttpBehavior类不是BehaviorExtensionElement的扩展。这是一个错误
<behaviors>
<endpointBehaviors>
<behavior name="customMyWebHttpBehavior">
<webHttp/>
<MyWebHttpBehavior/>
</behavior>
</endpointBehaviors>
<behaviors>
<bindings>
<webHttpBinding>
<binding name="webHttp"
maxReceivedMessageSize="20000000" >
<security mode="None">
<transport clientCredentialType = "None"/>
</security>
</binding>
<MyWebHttpBehavior />
</webHttpBinding>
</bindings>
<endpoint address="" binding="webHttpBinding" contract="Service.IService1" bindingConfiguration="webHttp" behaviorConfiguration="customMyWebHttpBehavior"/>