Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将自定义服务行为添加到WCF配置中_Wcf - Fatal编程技术网

如何将自定义服务行为添加到WCF配置中

如何将自定义服务行为添加到WCF配置中,wcf,Wcf,在Uri模板参数中有一个带有ComplexType的服务,我将CanConvert()和ConvertStringToValue()方法重写为MyQueryStringConverter类 我需要将该行为添加到web.config文件中 这就是行为 public class MyWebHttpBehavior : WebHttpBehavior { protected override QueryStringConverter GetQueryStringConverte

在Uri模板参数中有一个带有ComplexType的服务,我将CanConvert()和ConvertStringToValue()方法重写为MyQueryStringConverter类

我需要将该行为添加到web.config文件中

这就是行为

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"/>