[英]WCF add query parameter not expected in signature
I have a contract used in a WCF POST. 我有WCF POST中使用的合同。 During the call, I need to add an extra parameter that I cannot add in the signature, because I get disambiguation issues.
在通话期间,我需要添加一个我无法在签名中添加的额外参数,因为会出现歧义消除问题。
Contract: 合同:
[OperationContract]
[WebInvoke(UriTemplate = "", Method = "POST")]
Y Create(Stream x);
[OperationContract]
[WebInvoke(UriTemplate = "?cmd=put", Method = "POST")]
Y Create2(Stream x);
What I'm trying to do is to alter the WebOperationContext.Current.OutgoingRequest
to add this parameter, bool allowOverwrite
. 我正在尝试做的是更改
WebOperationContext.Current.OutgoingRequest
以添加此参数bool allowOverwrite
。
The only way to make it work was by adding a header, which is not a happy choice. 使其起作用的唯一方法是添加标题,这不是一个好选择。
WebOperationContext.Current.OutgoingRequest.Headers.Add(...)
Any idea how I can improve this? 知道我该如何改善吗?
Note: I cannot do major changes to the contract as it is mainly legacy code. 注意:我不能对合同进行重大更改,因为它主要是遗留代码。
You can install WCF Web Extensions nuget package ( nuget link ). 您可以安装WCF Web扩展 nuget软件包( nuget link )。 Then you will be able to add optional query parameters even outside an WebOperationContext scope, like this:
然后,您甚至可以在WebOperationContext范围之外添加可选的查询参数,如下所示:
using (var factory = new WebChannelFactory<IQueryParametersTestService>(new WebHttpBinding()))
{
factory.Endpoint.Address = new EndpointAddress(ServiceUri);
factory.Endpoint.EndpointBehaviors.Add(new QueryParametersServiceBehavior());
using (var client = factory.CreateWebChannel())
{
client.AddQueryParameter("format", "xml");
client.AddQueryParameter("version", "2");
var result = client.Channel.GetReport();
}
}
Server-side you can retrieve the optional query parameters using WebOperationContext. 在服务器端,您可以使用WebOperationContext检索可选的查询参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.