开发者

Adding querystring parameters to a WCF service operation that accepts Stream

开发者 https://www.devze.com 2023-02-06 06:00 出处:网络
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?

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:

  1. Mark the operation with a [WebInvoke] attribute that has a Method="POST" and a UriTemplate that includes your non-stream arguments in the querystring
  2. Set the endpoint's binding to webHttpBinding
  3. Add <webHttp/> to your endpoint's behaviorConfiguration
  4. 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)
0

精彩评论

暂无评论...
验证码 换一张
取 消