添加查询字符串参数来接受流WCF服务操作 [英] Adding querystring parameters to a WCF service operation that accepts Stream
问题描述
有什么办法来配置的WebHttpBinding WCF服务接受多个的查询字符串的参数,用流
参数是请求的身体?
Is there any way to configure a webHttpBinding WCF service to accept multiple querystring arguments, with a Stream
argument being the body of the request?
我想这样做没有从操作签名省去查询字符串参数,并从的OperationContext直接访问它们。
I'd like to do this without omitting the querystring arguments from the operation signature and accessing them from the OperationContext directly.
UriTemplate
似乎是显而易见的选择,但是这不仅导致AddressFilter不匹配的异常被抛出。
UriTemplate
seemed like the obvious choice, but that only results in AddressFilter mismatch exceptions being thrown.
移动参数传递给MessageContract wtih的MessageHeader属性在所有非流场,以避免流可以是唯一的参数的错误,会导致的MessageHeader属性不支持的WebHttpBinding一个错误。
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.
这是流不支持MessageContracts的WebScriptEnablingBehavior反正在MessageContract只留下流参数通知我。
Leaving only the Stream argument on the MessageContract informs me that Streams aren't supported in MessageContracts for WebScriptEnablingBehavior anyway.
有什么想法?
推荐答案
该解决方案是:
- 标记与
[WebInvoke]
属性,它有一个方法=POST
和操作UriTemplate
,其中包括在查询字符串 - 设置端点的结合
的WebHttpBinding
- 添加
< webHttp />
到您的端点的behaviorConfiguration - 设置
transferMode =流媒体
您端点的绑定配置
- 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
有些事情需要注意的:
- wsHttpEndPoint和basicHttpEndPoint不支持流,非流参数的组合。如果您需要SOAP +的WebHttpBinding,你需要使用两个服务接口和两个端点(尽管具体的实施可以共享)
- 的WSDL生成器不支持,要么,所以访问帮助页面(调用该服务将仍然被罚款,虽然)当你需要禁用MEX上webHttp端点或将引发异常
这篇关于添加查询字符串参数来接受流WCF服务操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!