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!
You'll have to resort to JSON, for example combined with the PUT or POST method. See this post for an explanation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With