![](/img/trans.png)
[英]Add/Change query string parameter in WCF BasicHttpBinding SOAP Call
[英]WCF add query parameter not expected in signature
我有WCF POST中使用的合同。 在通话期间,我需要添加一个我无法在签名中添加的额外参数,因为会出现歧义消除问题。
合同:
[OperationContract]
[WebInvoke(UriTemplate = "", Method = "POST")]
Y Create(Stream x);
[OperationContract]
[WebInvoke(UriTemplate = "?cmd=put", Method = "POST")]
Y Create2(Stream x);
我正在尝试做的是更改WebOperationContext.Current.OutgoingRequest
以添加此参数bool allowOverwrite
。
使其起作用的唯一方法是添加标题,这不是一个好选择。 WebOperationContext.Current.OutgoingRequest.Headers.Add(...)
知道我该如何改善吗?
注意:我不能对合同进行重大更改,因为它主要是遗留代码。
您可以安装WCF Web扩展 nuget软件包( nuget link )。 然后,您甚至可以在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();
}
}
在服务器端,您可以使用WebOperationContext检索可选的查询参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.