WCF WebInvoke with query string parameters AND message body

I am new to web services and especially WCF, so bear with me.

I am writing an API that takes several parameters, such as username, apikey and some parameters, but I also need to send it a string, which can be several thousand words, which is processed and transmitted as a stream. It didn't make sense to just put it in the query string, so I thought I just wanted the body of the message to be sent to the service.

There seems to be no easy way to do this ...

My job contract is as follows

[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 it works. But this is the β€œtext” parameter, which I want to pull out and have in the body of the message. One thing I read said that the thread has one more parameter, for example:

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

which I could then read. But this generates an error saying that if I want to have a stream parameter, then it should be the only parameter.

So, how can I achieve what I'm trying to do here, or is it not a big deal to send a few thousand words to the query string?

+4
source share
2 answers

Completing a solution simply using WebServiceHostFactory

-2
source

https://social.msdn.microsoft.com/Forums/vstudio/en-US/e2d074aa-c3a6-4e78-bd88-0b9d24b561d1/how-to-declare-post-parameters-in-wcf-rest-contract?forum= wcf

The best answer I could find that solves this problem and worked for me so that I can correctly adhere to RESTful standards

0
source

All Articles