0

I am not able to access any method with the attribute [webinvoke] in a RESTful WCF service.

My code is like this:

[OperationContract]
[WebInvoke(Method = "Post", UriTemplate = "Comosite/{composite}", ResponseFormat = WebMessageFormat.Xml)]
CompositeType GetDataUsingDataContract(string composite);        

On executing the above service I am getting an error message

Method not allowed.

I tried many ways, by modifying the urltemplate, method name and method type etc. but nothing is working out.

But if I use the [WebGet] attribute the the service method is working fine.

Can anybody suggest me what can I do make it work?

Thanks in advance... :)

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user1335978
  • 193
  • 4
  • 13
  • the thing is i want to perform post/put/delete operation. using get i can get the date from the service ,but the thing is i just dont want to get the data, i want to perform update and delete operations on the data. for that i was testing with webinvoke and post method. if post method works fine then i can proceed for delete and put methods. – user1335978 Apr 16 '12 at 12:08
  • Check this http://msdn.microsoft.com/en-us/library/bb472541(v=vs.90).aspx – Milee Apr 16 '12 at 12:20
  • Can you show some of the code you have used to call your service? – Bassetassen Apr 16 '12 at 18:22
  • I used HTTPClient object to communicate with the service. and it is working fine for Get method. – user1335978 Apr 17 '12 at 06:16
  • code for calling the service is as follows. – user1335978 Apr 17 '12 at 06:19
  • HttpClient http = new HttpClient("http://localhost:8732/Design_Time_Addresses/WCFRestService2/Service1/"); string value; Console.WriteLine("Enter a Input for Rest service2"); value = Console.ReadLine(); HttpResponseMessage resp = http.Post("Composite/" + value , HttpContent.CreateEmpty()); – user1335978 Apr 17 '12 at 06:21

2 Answers2

1

I created a similar service as you have done here and called it with fiddler and that worked when I changed the method to POST all capital letters. When method is like Post as in your code I get an endpoint not found message.

My fiddler request looked like this:

http://localhost/service/service1.svc/Comosite/test 

Here test is sent in as the composite parameter and I get a CompositeType as xml returned.

Bassetassen
  • 20,852
  • 8
  • 39
  • 40
1

Try changing

[WebInvoke(Method = "Post", UriTemplate = "Comosite/{composite}", ResponseFormat = WebMessageFormat.Xml)]

to

[WebInvoke(Method = "POST", UriTemplate = "Comosite/{composite}", ResponseFormat = WebMessageFormat.Xml)]
bristows
  • 736
  • 1
  • 7
  • 22