Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 84159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:53:13+00:00 2026-05-10T21:53:13+00:00

Using the WCF web programming model one can specify an operation contract like so:

  • 0

Using the WCF web programming model one can specify an operation contract like so:

[OperationContract] [WebGet(ResponseFormat = WebMessageFormat.Xml, UriTemplate = 'SomeRequest?qs1={qs1}&qs2={qs2}')] XElement SomeRequest1(string qs1, string qs2); 

Now if we had to make a contract that accepts an array of parameters with the same name (in this case qs1) contract like so…

[OperationContract] [WebGet(ResponseFormat = WebMessageFormat.Xml, UriTemplate = 'SomeRequest?qs1={qs1}&qs1={qs2}')]  XElement SomeRequest2(string qs1, string qs2); 

We get the error message at run time when we make the invocation to the method:

the query string must have ‘name=value’ pairs with unique names. Note that the names are case-insensitive. See the documentation for UriTemplate for more details.

How does one define an HTTP service that exposes a resource with an array of parameters without resorting to a loosey-goosey interface?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:53:14+00:00Added an answer on May 10, 2026 at 9:53 pm

    I’ve implemented a simple custom QueryStringConverter so that you can make qs1 an string[] then have the query string variable be comma delimited (e.g. http://server/service/SomeRequest?qs1=val1,val2,val3,val4)

    [OperationContract] [WebGet(ResponseFormat = WebMessageFormat.Xml,         UriTemplate = 'SomeRequest?qs1={qs1}')] XElement SomeRequest2(string[] qs1); 

    First you need a class that inherits from WebHttpBehavior so that we can inject our custom QueryStringConverter:

    public class CustomHttpBehavior : System.ServiceModel.Description.WebHttpBehavior {     protected override System.ServiceModel.Dispatcher.QueryStringConverter GetQueryStringConverter(System.ServiceModel.Description.OperationDescription operationDescription)     {         return new CustomQueryStringConverter();     } } 

    Then our CustomQueryStringConverter that handles string[] parameters:

    public class CustomQueryStringConverter : System.ServiceModel.Dispatcher.QueryStringConverter {     public override bool CanConvert(Type type)     {         if (type == typeof(string[]))         {             return true;         }          return base.CanConvert(type);     }      public override object ConvertStringToValue(string parameter, Type parameterType)     {         if (parameterType == typeof(string[]))         {             string[] parms = parameter.Split(',');             return parms;         }          return base.ConvertStringToValue(parameter, parameterType);     }      public override string ConvertValueToString(object parameter, Type parameterType)     {         if (parameterType == typeof(string[]))         {             string valstring = string.Join(',', parameter as string[]);             return valstring;         }          return base.ConvertValueToString(parameter, parameterType);     } } 

    The last thing you need to do is create a behavior configuration extension so that the runtime can get an instance of the CustomWebHttpBehavior:

    public class CustomHttpBehaviorExtensionElement : System.ServiceModel.Configuration.BehaviorExtensionElement {     protected override object CreateBehavior()     {         return new CustomHttpBehavior();     }      public override Type BehaviorType     {         get { return typeof(CustomHttpBehavior); }     } } 

    Now we add the element to our configuration extensions so that our CustomWebHttpBehavior is used, we use the Name of that extension instead of <webHttp /> in our behavior:

     <system.serviceModel>    <services>      <service name='NameSpace.ServiceClass'>        <endpoint address='' behaviorConfiguration='MyServiceBehavior'         binding='webHttpBinding' contract='NameSpace.ServiceClass' />      </service>    </services>   <behaviors>    <endpointBehaviors>     <behavior name='MyServiceBehavior'>       <customWebHttp/>     </behavior>    </endpointBehaviors>   </behaviors>   <extensions>     <behaviorExtensions>       <add name='customWebHttp' type='NameSpace.CustomHttpBehaviorExtensionElement, MyAssemblyName' />     </behaviorExtensions>   </extensions>   <serviceHostingEnvironment aspNetCompatibilityEnabled='true' />  </system.serviceModel> 

    You can now also extend your CustomQueryStringConverter to handle other types that the default one doesn’t, such as nullable value types.

    NOTE: There is a bug logged at microsoft connect that directly relates to this code. The code does not actually work in almost all circumstances where you attempt to Query Convert different types.

    http://connect.microsoft.com/VisualStudio/feedback/details/616486/bug-with-getquerystringconverter-not-being-called-by-webservicehost#tabs

    Please make sure you read this carefully before wasting hours of your time creating custom REST query string converters that cannot possibly work. (Applies to Framework 4.0 and below).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 57k
  • Answers 57k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The extract and extractall methods are great if you're on… May 11, 2026 at 8:23 am
  • added an answer Thank you all. I tried grillix's idea of setting the… May 11, 2026 at 8:23 am
  • added an answer There is a way to do it in IE by… May 11, 2026 at 8:23 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.