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