views:

65

answers:

2

I have developed a rest web service by using the following link

http://www.c-sharpcorner.com/UploadFile/dhananjaycoder/simplerestservice11172009221218PM/simplerestservice.aspx

Now, I am passing parameters to this rest web service by using URL. I am passing parameters as follows

http://localhost:50362/PMTSRest/Service.svc/GetProjects?ProjectID=1

Now I want to know is there any way to remove the question mark in the URL & instead of it use any other symbol or how to pass parameters to the rest web service without using the (?) symbol ? Can you please provide me any code or link through which I can resolve the above issue?

A: 

I think you are asking how to put the parameters in a path segment. e.g.

[ServiceContract]
public interface ISearch
{
    [OperationContract]
    [WebGet(UriTemplate = "/Search/{name}", BodyStyle = WebMessageBodyStyle.Bare)]
    string  GetGreeting(string name);
}

Is this what you are looking for?

Darrel Miller
yes, but how to pass the same variable if it is int ? (In the above case name is string). I am trying for int variable but it is giving error Operation 'GetTasksForThisProject' in contract 'ISearch' has a path variable named 'ProjectID' which does not have type 'string'. Variables for UriTemplate path segments must have type 'string'.
Shailesh Jaiswal
I am using following code
Shailesh Jaiswal
[OperationContract] //[WebGet(UriTemplate = "/GetTasksForThisProject?ProjectID={ProjectID}", BodyStyle = WebMessageBodyStyle.Bare)] [WebInvoke(Method = "GET", //UriTemplate = "/GetTasksForThisProject?ProjectID={ProjectID}", UriTemplate = "/GetTasksForThisProject/{ProjectID}", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)] List<Task> GetTasksForThisProject(int ProjectID);
Shailesh Jaiswal
@Shailesh Accept the parameter as a string and then do int.Parse()
Darrel Miller
Yes, I got your answer. Thanks a lot
Shailesh Jaiswal
A: 

Maybe use HTTP POST instead HTTP GET to hide these parameters?

bassfriend