Not able to access any mothod with the attribute [WebInvoke] in WCF Restful services

StackOverflow https://stackoverflow.com/questions/10172036

  •  31-05-2021
  •  | 
  •  

Вопрос

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... :)

Это было полезно?

Решение

Try changing

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

to

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

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top