Click here to Skip to main content
15,884,473 members
Articles / Hosted Services / Azure

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

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
23 Jul 2010CPOL3 min read 13.1K   3   2
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.

This article was originally posted at http://www.atulverma.com/feeds/posts/default

License

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


Written By
Software Developer (Senior)
India India
Atul works at Microsoft as a .NET consultant. As a consultant his job is to design, develop and deploy enterprise level secure and scalable solutions using Microsoft Technologies.

His technical expertise include .NET Framework(4.0, 3.5, 3.0), WPF, WCF, SharePoint 2010, ASP.net, AJAX, Web Services, Enterprise Applications, SQL Server 2008, Open Xml, MS Word Automation.

Follow him on twitter @verma_atul

He blogs at
http://www.atulverma.com
http://blogs.msdn.com/b/atverma

Comments and Discussions

 
GeneralAbsolutely Right. I found the same thing. Pin
Brijesh Shah31-Jul-10 3:04
Brijesh Shah31-Jul-10 3:04 
GeneralRe: Absolutely Right. I found the same thing. Pin
atverma31-Jul-10 3:21
atverma31-Jul-10 3:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.