Is there any way to configure a webHttpBind开发者_如何转开发ing WCF service to accept multiple querystring arguments, with a Stream
argument being the body of the request?
I'd like to do this without omitting the querystring arguments from the operation signature and accessing them from the OperationContext directly.
UriTemplate
seemed like the obvious choice, but that only results in AddressFilter mismatch exceptions being thrown.
Moving the arguments to a MessageContract wtih MessageHeader attributes on all non-Stream fields, in order to avoid the "Stream can be the only argument" error, causes an error that MessageHeader attributes aren't supported with webHttpBinding.
Leaving only the Stream argument on the MessageContract informs me that Streams aren't supported in MessageContracts for WebScriptEnablingBehavior anyway.
Any thoughts?
The solution to this is:
- Mark the operation with a
[WebInvoke]
attribute that has aMethod="POST"
and aUriTemplate
that includes your non-stream arguments in the querystring - Set the endpoint's binding to
webHttpBinding
- Add
<webHttp/>
to your endpoint's behaviorConfiguration - Set
transferMode="Streamed"
on your endpoint's binding configuration
And some things to be aware of:
- wsHttpEndPoint and basicHttpEndPoint don't support a mix of stream and non-stream arguments. If you need SOAP + webHttpBinding, you'll need to use two service interfaces and two endpoints (though the concrete implementation can be shared)
- The WSDL generator does not support it either, so you'll need to disable mex on the webHttp endpoint or an exception will be thrown when accessing the help page (calling the service will still be fine, though)
精彩评论