开发者

WCF Rest Custom URL

开发者 https://www.devze.com 2023-02-13 17:49 出处:网络
I\'m trying to configure a RESTful WCF service that will accept the following url: http://localhost/Service.svc/ProcessRequest;ID=1234

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 ;开发者_如何学GoID=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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消