wcfpostwebinvoke

WCF WebInvoke with query string parameters AND a post body


I'm fairly new to web services and especially WCF so bear with me.

I'm writing an API that takes a couple of parameters like username, apikey and some options, but I also need to send it a string which can be a few thousands words, which gets manipulated and passed back as a stream. It didn't make sense to just put it in the query string, so I thought I would just have the message body POSTed to the service.

There doesn't seem to be an easy way to do this...

My operation contract looks like this

[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate="Method1?email={email}&apikey={apikey}"+
"&text={text}&quality={qual}", BodyStyle = WebMessageBodyStyle.Bare)]
Stream Method1(string email, string apikey, string text, string qual);

And this works. But it is the 'text' parameter I want to pull out and have in the post body. One thing I read said to have a stream as another parameter, like this:

Stream Method1(string email, string apikey, string qual, Stream text);

which I could then read in. But that throws an error saying that if I want to have a stream parameter, that it has to be the only parameter.

So how can I achieve what I am trying to do here, or is it no big deal to send up a few thousand words in the query string?


Solution

  • Ended up solving simply by using WebServiceHostFactory