WCF message with query string

I am currently developing a WCF service maintained by the Windows Service. One method has a URI that is configured to receive a callback from a payment provider. This is an interface contract ...

[OperationContract] [WebInvoke(UriTemplate = "3DSecureCallback?TrxId={id}", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare)] void ThreeDSecureCallBack(string id, Stream body); 

This problem that I am facing is that a third-party provider is sent to our service. I have to provide a callback url. Thus, we can reconcile payments, we provide a URL with a query string parameter containing a transaction identifier.

Callbacks were successful during the development of this service. (This was before the Steam option was added)

However, we are now at the stage when we need to analyze published data. It is that the parameter of the 2nd “stream” has been added to the method signature.

The problem I am getting is that I am getting the following exception ...

 For request in operation ThreeDSecureCallBack to be a stream the operation must have a single parameter whose type is Stream. 

By removing the id parameter and having only a stream, we can get the data to send. This will not work in practice, although I also need to request a string parameter.

Can anyone advise how to solve this problem? I am really at a loss.

Thanks in advance,

David

+3
source share
2 answers

You can access the id value below

WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["id"]

Now you can have only one parameter for your type stream method.

+8
source

Awakening the old thread, but thought it would be useful to document another way to do this.

Changing the BodyStyle of the WeInvoke method to Wrapped will solve your problem where it is assumed that any parameters that you do not specify on the UriTemplate come from the request body.

The only drawback is that you will also have to wrap your message data ... and use the built-in data types as additional parameters or define your own suitable DataContract.

Example:

 [DataContract] public class PostInfo { [DataMember] public string Info1; [DataMember] public string Info2; } [OperationContract] [WebInvoke(UriTemplate = "3DSecureCallback?TrxId={id}", Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped)] void ThreeDSecureCallBack(string id, PostInfo body); 

Source: msdn forums

+3
source

Source: https://habr.com/ru/post/921699/


All Articles