1
votes

I have created a WCF web service inside a web role in an Azure Cloud Service. I verified the completeness of the implementation by deploying the cloud service on the cloud and having a client application call the service. However, when I look into web.config of the web role that hosts the WCF web service, I could not find any reference to the Web service. Where can I find the configuration related to the web service? Aparently, web services hosted within web role use HTTP binding; I need to change the binding of my service to use JSON for all communication. Can you please tell me how to achieve this.

1

1 Answers

1
votes

You're probably using basicHttpBinding now - that's what WCF defaults to for HTTP. The reason you don't see a reference to your service in web.config is because of the simplified configuration that was introduced in .NET Framework 4.0. You can still explicitly configure the service in web.config like you had to in earlier versions if you want, but it's not necessary.

To do what you're asking, here's what you need to do:

Change the protocolMapping to use webHttpBinding instead of basicHttpBinding.

enter image description here

Add a webHttp endpoint behavior and set the DefaultOutgoingResponseFormat to "Json".

enter image description here

Change your .svc markup file to include the Factory attribute and specify the WebServiceHostFactory. For example:

Factory="System.ServiceModel.Activation.WebServiceHostFactory"

Finally, add the [WebGet] attribute to your methods in the service contract.