1

I'm about to set up a RESTful web service in WCF.

My question is how can you create a Service Host using a Service contact as the basis of the request, but also pass in additional parameters in the querystring that are not declared in the contact.

Can you access the headers to access the querystring from the service implementation? Is there a way of intercepting the request and compiling a Dictionary for the additional querystring params, and then pass this in to the operation?

Here's a sample ServiceContact I found.

[ServiceContract]
public interface ITest
{
  [OperationContract]
  [WebGet(UriTemplate = "Test?format=XML&code={code}", ResponseFormat = WebMessageFormat.Xml)]
  string TestXml(string code);
}

Taking this example I'd either need to be able to access the querystring params from the TestXml method or pass an additional dictionary/generic object as a parameter.

Thanks in advance,

Sam

1
  • I've just seen article where it was suggested using POST and passing an XML or JSON string to hold the extra values. I'm going to try that, but would still be interested as to how it could be done using GET. Mar 30, 2012 at 10:03

1 Answer 1

1

I've found the way to do it

http://www.west-wind.com/weblog/posts/2011/Jan/10/Allowing-Access-to-HttpContext-in-WCF-REST-Services

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.