WCF 400 Bad Request

I created a simple function

[OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)] string Start(); 

Definition

  public String Start() { JavaScriptSerializer serializer = new JavaScriptSerializer(); return serializer.Serialize("Check"); } 

From a browser using Javascript / JQuery, http: //localhost/service1.svc tells me that I created the service and all the other information. Looks nice.
I am trying to call it using http: //localhost/service1.svc/Start

I get 400 bad requests for this call. Hope I'm not doing anything wrong here. Should I have access to the WCF service from a browser? I tried searching a lot before I thought about publishing. But I can’t understand that this basic work upsets me.

EDIT and UPDATE Now I'm at this point. The service page indicates that the metadata service is disabled and asks me to insert the following text

  <serviceMetadata httpGetEnabled="true" /> 

I inserted the text - but still it shows the same text !! This is getting too confusing now.

+4
source share
2 answers

Try changing the POST using GET and restart the request

+1
source

It works for me. I created WCF Recreation.

I am using a URL that looks like http: // localhost: 8080 / Service1 / Start

Here is the code:

 using System.ServiceModel; using System.ServiceModel.Activation; using System.ServiceModel.Web; using System.Web.Script.Serialization; namespace WcfRestService1 { // Start the service and browse to http://<machine_name>:<port>/Service1/help to view the service generated help page // NOTE: By default, a new instance of the service is created for each call; change the InstanceContextMode to Single if you want // a single instance of the service to process all calls. [ServiceContract] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] // NOTE: If the service is renamed, remember to update the global.asax.cs file public class Service1 { [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json)] public string Start() { JavaScriptSerializer serializer = new JavaScriptSerializer(); return serializer.Serialize("Check"); } } } 
+1
source

All Articles