Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map URI parameters to properties of parameter object?

I am trying to create a WCF service which provides a SOAP and a JSON endpoint.
For mapping the parameters of the request URL to the method parameters, I use the WebGetAttribute's UriTemplate method.

This works fine for methods expecting parameters of simple data types.

However, the following method expects a complex object and I don't want to change it because of the SOAP-part of the service:

[OperationContract]
Person Test(TestParameters parameters);

while TestParameters looks like (with a larger number of properties):

[DataContract]
public class TestParameters
{
    [DataMember]
    public string First
    {
        get;
        set;
    }
    [DataMember]
    public string Second
    {
        get;
        set;
    }
}

When calling the method via GET now, I would like to be able to initialize parameters.First and parameters.Second from the request URI, e.g.

/Test?first=Foo&second=Bar

I already tried applying

[WebGet(UriTemplate = "/Test?first={parameters.First}&second={parameters.Second})]

to the method.
However, this syntax doesn't seem to be supported by WCF. The error message says:

System.InvalidOperationException: Operation 'Test' in contract 'IService1' has a UriTemplate that expects a parameter named 'PARAMETERS.FIRST', but there is no input parameter with that name on the operation.

Is there any other syntax which allows formulating URI parameter mapping to properties of parameter objects?

Otherwise, do you know whether this behavior could be added easily?

Many thanks in advance for your responses!

like image 448
Matthias Avatar asked Nov 13 '22 12:11

Matthias


1 Answers

You'll have to resort to JSON, for example combined with the PUT or POST method. See this post for an explanation.

like image 79
diggingforfire Avatar answered Nov 16 '22 02:11

diggingforfire