I hate WCF setup with endpoints, behaviors etc. I believe all these things should be performed automatically. All I want to do is to return JSON result from my WCF service. Here
Take a look at this SO question.
Edit: Since you're not specifying an address for your service, try hitting: http://localhost:22059/ZombieService.svc/KnownZombies (with the .svc).
I also think you need the <webHttp />
behavior added to your specified endpoint behavior.
Edit: Try changing your endpoint definition to this:
<service
name="HighOnCodingWebApps.ZombieService"
behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint
address=""
binding="webHttpBinding"
behaviorConfiguration="SomeBehavior"
bindingConfiguration="default"
contract="HighOnCodingWebApps.IZombieService" />
</service>
In your WebGet
or WebInvoke
Specify your BodyStyle
to WrappedRequest
, then remove the UriTemplate
. When Invoking your service use the function name.
Hope it helps.
Example:
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
void register(string name, string surname);
You are using the WebInvokeAttribute which tells WCF by default to accept POST as the verb. Since you are trying to access it via a GET action, it is being ignored.
Use WebGetAttribute instead.
Per MSDN:
If you want a service operation to respond to GET, use the WebGetAttribute instead.
Have you tried the WCF SvcConfigEditor? It is available from the Tools menu in Visual Studio. Open your web/app.config with SvcConfigEditor to get GUI help on getting everything right.
I am using .net framework 4, VS2010. I made a dummy mistake in my global.asax.cs that instead of creating an instance of WebServiceHostFactory I punched WebScriptServiceHostFactory through intellSense. As a result I got the same error:
Endpoints using 'UriTemplate' cannot be used with 'System.ServiceModel.Description.WebScriptEnablingBehavior'.
I corrected the instance to WebServiceHostFactory in my global.asax.cs, I don't see the error anymore.
Just use ASP.NET Web API instead of WCF