Using WCF REST with POST
I have an WCF service which is working mostly with GET but one contract should work with POST. I can't get it working - it returns "405 Method Not Allowed" all the time.
The service should recieve JSON and return a JSON.
I guess it something with the configuration. Here is my web.config file:
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibility开发者_如何学PythonEnabled="true"
multipleSiteBindingsEnabled="true" />
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false" defaultOutgoingResponseFormat="Json" />
</webHttpEndpoint>
</standardEndpoints>
and the service itself
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "LoginUser", BodyStyle=WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, RequestFormat=WebMessageFormat.Json)]
public int Login(string user, string password)
{ .... }
Any ideas? Help would be much appreciated!
Make sure that you're really making a POST. Because your code seems valid.
Try it by creating a new html-file containing something like:
<form action="http://{Address to your service}/Service.svc/LoginUser" method="POST">
<input type="submit" value="Fire away!" />
</form>
Check out my comments for the duplicates but it boils down to making sure you have the correct verb supplied in your operation contract. Here is an example:
[ServiceContract(Namespace = "http://www.test.com/youruri")]
public interface ISomeService
{
[OperationContract]
[WebInvoke(Method = "POST")]
string SomeMethod();
}
精彩评论