This blog is regarding my first attempt to explore “Hosting a service in Azure using WCF and Visual Studio 2010”, the issue I faced and the quick fixes required to make it running. You can explore the Windows Azure Platform here.
I faced a few issues and am sharing the workarounds. I won’t get into details in this post, so I will keep things simple and target the workarounds only.
- Run Visual Studio 2010 with elevated permission, e.g., “Run as Administrator” option, otherwise you will get a prompt as displayed below when creating/opening the Windows Azure Cloud Service project.
You may need to install Windows Azure Tools for Microsoft Visual Studio to enable the creation, configuration, building, debugging, running and packaging of scalable web applications and services on Windows Azure. You can download Windows Azure Tools for Microsoft Visual Studio 1.1 from here.
r
- Create a New Project. Select Cloud from Installed Templates and then select Windows Azure Cloud Service and click Ok.
- Select the WCF Service Web Role as we are exposing service using WCF. I’ll go with the default code that gets generated and without making any change according to the context of this Blog. Build and run the application.
- In order to test the WCF services, we will use Microsoft WCF Test Client. This can be opened as displayed below:
- We need to Add the Service to test by right clicking on the My Service Projects and then clicking Add Service. Here we need to specify the end point address, e.g., in my case, it was “//127.0.0.1:81/Service1.svc?wsdl”
- In case you see the error, “Service metadata may not be accessible”, as displayed below, we need to add a Service Behaviour in the Web.Config file as displayed in the next step:
- The section displayed in green font is required to resolve the error in the above step. This is a known issue and there is a patch available for it here. You may see that IDE doesn’t recognize it. It shows a Warning, so ignore the warning.
<serviceBehaviors>
<behavior name="WCFServiceWebRole1.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<add scheme="http" port="81" />
<add scheme="https" port="444" />
</defaultPorts>
</useRequestHeadersForMetadataAddress>
</behavior>
</serviceBehaviors>
- Now when you run, you may see the error displayed below in the browser. This is a known issue and there is a patch available for it here. Install this patch and after installation, restart your machine.
- Now, when you run the application, it will run fine so it’s time to test it using Microsoft Windows Test Client. In case WCF HTTP Activation is turned off, you may now see this error while trying to Add the service to test as in Step 5:
- In Order to resolve the error above, just turn on the WCF HTTP activation in “Turn Windows Features on and off” which is turned off as in the image displayed below:
- Now add the service to the WCF test client as in Step 5. Voila, finally everything is working fine. In order to test your WCF service, choose any of the Operations, e.g.
GetData()
in this case, double click it, specify the Value in Request section, e.g., I have specified 23 and click Invoke. In the Response, you will see the results:
- At runtime, WCF services may return the following error: The message with To 'http://127.0.0.1:81/Service.svc' cannot be processed at the receiver, due to an
AddressFilter
mismatch at the EndpointDispatcher
. Check that the sender and receiver's EndpointAddresses
agree. The error can be corrected by applying the following attribute to the service class.
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
This concludes the article as we have Service hosted in Microsoft Azure platform and exposed using WCF and Visual Studio 2010. Time to explore the advanced features of Azure platform.
CodeProject