I have a contract used in a 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
.
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). Then you will be able to add optional query parameters even outside an WebOperationContext scope, like this:
Server-side you can retrieve the optional query parameters using WebOperationContext.