Mark 909
Mark 909

Reputation: 1835

WCF Rest Custom URL

I'm trying to configure a RESTful WCF service that will accept the following url:

http://localhost/Service.svc/ProcessRequest;ID=1234

I've created the Service Contract as follows:

[ServiceContract]
    public interface IService
    {

        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "/ProcessRequest")]
        XmlElement ProcessRequest(Stream postbody);

However, this returns a 404 error when I try and call this from the client, probably due to the format of the url. Is there a way of handling the ;ID=1234 as part of method. I don't necessarily need to capture the value of ID, but for various reasons the client will be sending the URL in that format and I must be able to handle it.

Upvotes: 0

Views: 1353

Answers (1)

Richard Szalay
Richard Szalay

Reputation: 84724

First up, you need to remove the / prefix from your UriTemplate. I'm not sure if you can get away with the semi-colon, but you should try this:

[ServiceContract]
public interface IService
{
    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "ProcessRequest;ID={id}")]
    XmlElement ProcessRequest(string id, Stream postbody);
}

Failing that, replace ; with ? and try loading it as http://localhost/Service.svc/ProcessRequest;ID=1234 to see if that's the problem.

Upvotes: 1

Related Questions