5
Answers

Problems in cosuming wcf Restful Service

amrish kumar

amrish kumar

9y
398
1
When Ever im trying to consume  my wcf restful service with Post Method it gives Exception

The remote server returned an error: (404) Not Found. 

But when i use Get Method in service it works  fine.
 
  Service
 
[OperationContract]
[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped,  Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "UserLogin/{emailId}/{password}")]
int UserLogin(string emailId, string password);
 
  
 
This is client application
 
var request = (HttpWebRequest)WebRequest.Create("http://localhost/GMTSService/GMTSService.svc/UserLogin/" + "user1"+ "passowrd");
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream strm = response.GetResponseStream();
StreamReader strmReader = new StreamReader(strm);
string txt = strmReader.ReadToEnd();
Response.Write(txt);
 
 
 Please Help me to resolve this.
 
 
Answers (5)
0
amrish kumar

amrish kumar

NA 56 2k 9y
i have soled the problem.
I was passing int in parameter,
but when i passed the value in string it resolve the error.
 
Thanks Manas Mohapatra for your response. 
0
amrish kumar

amrish kumar

NA 56 2k 9y
Hi
I Used request.Method = "POST";  abut error have not solved
0
Manas Mohapatra

Manas Mohapatra

NA 29.3k 3.3m 9y
Hi,
 
Please add following code after creating request object:
 
request.Method = "POST"; 
0
amrish kumar

amrish kumar

NA 56 2k 9y
Thank you for your quick Response
By My Service is worked when im using Get Method in Service.
But it Doesnt work when im trying to use post Method.
0
Manas Mohapatra

Manas Mohapatra

NA 29.3k 3.3m 9y
Hi,
 
As per your error, your url is not correct.
 
When you are creating  WebRequest.Create("") and passing the string path - this is not correct.
 
Please recheck it. 
 
Secondly your service should be in running mode.