1

I had a WCF Service

My Web.config looks like this:

<system.serviceModel>

<bindings>
  <webHttpBinding>
    <binding name="crossDomain" crossDomainScriptAccessEnabled="true"  />
  </webHttpBinding>
</bindings>

<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="EndpBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>

<services>
  <service behaviorConfiguration="ServiceBehavior"  name="MyNameSpace.MyService">
    <endpoint address="" binding="webHttpBinding"  bindingConfiguration="crossDomain" contract="MyNameSpace.IMyService"  behaviorConfiguration="EndpBehavior"/>
  </service>
</services>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

I recently found this code for array parameter from one of the website

using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Web;

namespace ArraysInQueryStrings
{
public class ArrayInQueryStringWebHttpBehavior : WebHttpBehavior
{
    WebMessageFormat defaultOutgoingResponseFormat;
    public ArrayInQueryStringWebHttpBehavior()
    {
        this.defaultOutgoingResponseFormat = WebMessageFormat.Json;
    }

    public override WebMessageFormat DefaultOutgoingResponseFormat
    {
        get
        {
            return this.defaultOutgoingResponseFormat;
        }
        set
        {
            this.defaultOutgoingResponseFormat = value;
        }
    }

    protected override QueryStringConverter GetQueryStringConverter(OperationDescription operationDescription)
    {
        return new ArrayQueryStringConverter();
    }
}
}

How to use this extended class in the web.config.

It seems to be an Endpoint behaviour but dont know how to use it.

Any help is appreciated

Moons
  • 3,833
  • 4
  • 49
  • 82
  • What exactly are you trying to accomplish? I think you might be taking the wrong path. – Sam Aleksov Jul 19 '13 at 08:08
  • My Services are correctly working. I created a function that will accespt array and i got the error but type 'System.String[]' is not convertible by 'QueryStringConverter'. So i found the solution is to update webhtppbehaviour. – Moons Jul 19 '13 at 08:20

1 Answers1

2

To add custom behaviors, you need to add your derived behavior as a behavior extension in config file and need to add a new Behavior extension type. Refer to this post - Custom Behavior won't register in my web.config

 public class ArrayInQueryStringBehaviorExtension : BehaviorExtensionElement
{
 public override Type BehaviorType
 {
    get { return typeof(ArrayInQueryStringWebHttpBehavior); 
 }
}

protected override object CreateBehavior()
{
    return new ArrayInQueryStringWebHttpBehavior();
}
}

Config file (you need to specify your assembly name where I have marked square brackets below)

<extensions>
  <behaviorExtensions>
    <add name=" ArrayInQueryStringWebHttpBehavior " type="[Namespace]. ArrayInQueryStringBehaviorExtension, [Assembly Name], [Assembly Version], [Assembly Culture], PublicKeyToken=null" />
  </behaviorExtensions>
</extensions>
<behaviors>
  <endpointBehaviors>
    <behavior name="arrayInQueryBehavior">
      <webHttp/>
      < ArrayInQueryStringWebHttpBehavior />
    </behavior>
  </endpointBehaviors>
<behaviors>
Community
  • 1
  • 1
vibhu
  • 1,657
  • 2
  • 15
  • 19
  • I already tried this before posting my question but i am not getting it. I had write almost all the code in the question. can you please tell me what addition i need to write based upon my question – Moons Jul 19 '13 at 12:08
  • I have mentioned some code above which you can try. Config file key has places where you need to mention namespace and assembly correctly. Let me know if it works for you – vibhu Jul 19 '13 at 15:49