Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Hosted-services / Azure

How to host a service in Azure and expose using WCF and Visual Studio 2010: Issues Faced and Quick Fixes

5.00/5 (1 vote)
23 Jul 2010CPOL3 min read 13.4K  
How to host a service in Azure and expose using WCF and Visual Studio 2010

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.

  1. 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.

    imager

  2. Create a New Project. Select Cloud from Installed Templates and then select Windows Azure Cloud Service and click Ok.

    image

  3. 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.

    image

  4. In order to test the WCF services, we will use Microsoft WCF Test Client. This can be opened as displayed below:

    image

  5. 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

    image

  6. 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:

    image

  7. 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.
    XML
    <serviceBehaviors> 
      <behavior name="WCFServiceWebRole1.Service1Behavior"> 
                <!-- To avoid disclosing metadata information, 
    		set the value below to false and remove the 
    		metadata endpoint above before deployment --> 
        <serviceMetadata httpGetEnabled="true"/> 
        <!-- To receive exception details in faults for debugging purposes, 
    	set the value below to true.  Set to false before deployment 
    	to avoid disclosing exception information --> 
        <serviceDebug includeExceptionDetailInFaults="false"/> 
        <useRequestHeadersForMetadataAddress> 
          <defaultPorts> 
            <add scheme="http" port="81" /> 
            <add scheme="https" port="444" /> 
          </defaultPorts> 
        </useRequestHeadersForMetadataAddress> 
      </behavior>        
    </serviceBehaviors>
  8. 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.

    image

  9. 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:

    image

  10. 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:

    image

  11. 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:

    image

  12. 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.
    C#
    [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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)