Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using a rest service to access a method with GET..It works fine When i run that method throught the browser ,but it crashes and gives an exception message when i run it thro the client code


string Orderid = 12345
uri = "http://localhost/Rest/RestServiceImpl.svc/testGEt/orderid/" + Orderid;


try
{
var xx = wc.UploadString(uri, "GET");
}
catch (Exception ex)
{
//Exception is ->>> The remote server returned an error: (405) Method Not Allowed.
}

Can any one help ??
Posted
Comments
SomeGuyThatIsMe 14-Nov-13 13:26pm    
Did you set the access control allow origin: * in your http headers on the server?
jayapen 14-Nov-13 13:29pm    
Sorry could u tell me how to do this ..

I can access the same service by the code below

uri = "http://localhost/Rest/RestServiceImpl.svc/testGEt/orderid/" + Orderid;
string strResult = string.Empty;
// declare httpwebrequet wrt url defined above
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(uri);
// set method as post
webrequest.Method = "GET";
// set content type
//webrequest.ContentType = “application/x-www-form-urlencoded”;
// declare & read response from service
HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
// set utf8 encoding
Encoding enc = System.Text.Encoding.UTF8;

// read response stream from response object
StreamReader loResponseStream = new StreamReader(webresponse.GetResponseStream(), enc);
// read string from stream data
strResult = loResponseStream.ReadToEnd();
// close the stream object
loResponseStream.Close();
// close the response object
webresponse.Close();
// assign the final result to text box
//txtResult.Text = strResult;
return strResult;
SomeGuyThatIsMe 14-Nov-13 14:14pm    
http://lmgtfy.com/?q=access+control+allow+origin+header

where is the client that isnt working sitting?
jayapen 14-Nov-13 14:20pm    
Thats also in my localmachine Below is the contract for that


[OperationContract(Name = "testGEt")]

[WebInvoke(Method = "GET", UriTemplate = "testGEt/OrderID/{orderid}", ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)]
string testGEt(string orderid);


SomeGuyThatIsMe 14-Nov-13 15:01pm    
Here is how i define one of my test methods, the RequestFormat may be causing you an issue i've never used it.

[OperationContract (Name="xmlData")]
[WebInvoke (Method = "GET",
UriTemplate = "xml/{id}",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Xml)]
string XMLData (string id);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900