WCF Post with Query String

David Muir picture David Muir · Jun 29, 2012 · Viewed 7.4k times · Source

I am currently developing a Windows Service hosted WCF service. One of the methods has a URI which is set up to receive a callback from a payment provider. This is the interface contract...

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

This issue I am having is that the 3rd party provider posts to our service. I have to provide a callback url to it. So we can reconcile payments, we provide a URL with a query string parameter containing the transaction id.

During development of this service, the call backs have been successful. (This was prior to adding the Steam parameter)

However, we are now at the stage where we need to parse the posted data. This is the point that the 2nd 'Stream' parameter was added to the method signature.

The issue that I am getting is that I receive 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 stream only, we can get the post data. This won't work in practice though as I need to query string paramter also.

Can anyone advise on how to resolve this issue please? I am really at a loss.

Thanks in advance,

David

Answer

Rajesh picture Rajesh · Jun 29, 2012

You can access the querystring "id" value as shown below

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

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