IT tutorials
 
Applications Server
 

SharePoint Applications Using Windows Azure : Create a WCF Service and Deploy It to Windows Azure

11/30/2012 6:05:49 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Create a WCF Service and Deploy It to Windows Azure

  1. Open Visual Studio 2010.

  2. Click File | New Project, select Cloud, and then select Windows Azure Cloud Service.

  3. Provide a name for your service (such as AzureMortgageService), and click OK.

  4. When prompted with the New Cloud Service Project dialog box, select WCF Service Web Role (as shown earlier in Figure 1) and click the right arrow button to add a new service to the project.

  5. Before clicking OK, point to the new service and then click the pencil icon to rename the service (for example, AzureMortgage).

    image with no caption
  6. Click OK.

  7. As an optional step, you can rename your service from the default Service1 to another name (such as AzureService). This is a best practice, especially when you’re deploying multiple services to Microsoft SharePoint. First, it’s much easier to work with multiple services if their titles are intuitive, and second, if you amend the web.config file in SharePoint, it’ll make it much easier to distinguish the client endpoint references. To change the service name, click the Service1 or IService1 references in your code, click the Refactor menu option, and then select Rename. Provide a new name for your service contract and code references. Visual Studio updates your project.

  8. After the project has been created, open the Service contract file (for example, IAzureService.cs) and amend the existing service contract as shown in the bolded code in the following code listing:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using System.Text;
    
    namespace AzureMortgage
    {
        [ServiceContract]
        public interface IAzureService
        {
            [OperationContract]
            double[] getDailyInterestRate();
        }
    }
  9. Now open the core service code file (for example, AzureService.svc.cs) and amend the service code with the bolded code as shown here:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using System.Text;
    
    namespace AzureMortgage
    {
        public class AzureService : IAzureService
        {
            public double[] getDailyInterestRate()
            {
                double dblDailyInterestRate = 0.00;
                dblDailyInterestRate = getTheDailyInterestRate();
    
                double[] returnProductCosts = new double[6];
    
                returnProductCosts[0] = dblDailyInterestRate + .24;
                returnProductCosts[1] = dblDailyInterestRate + .20;
                returnProductCosts[2] = dblDailyInterestRate + .19;
                returnProductCosts[3] = dblDailyInterestRate + .17;
                returnProductCosts[4] = dblDailyInterestRate + .16;
                returnProductCosts[5] = dblDailyInterestRate + .13;
    
                return returnProductCosts;
            }
    
            private double getTheDailyInterestRate()
            {
    
                return .13;
            }
        }
    }

    The service code returns a one-dimensional array made up of six variables of type double. Each of these doubles essentially represents an interest rate for a specific mortgage product that is based on a daily interest rate (which would of course fluctuate over time but in this example is hard-coded for illustrative purposes). For example, each of the elements within the array is initialized to be a specific rate based on the daily interest rate (dblDailyInterestRate) as shown in the following code snippet:

    returnProductCosts[0] = dblDailyInterestRate + .24;
    returnProductCosts[1] = dblDailyInterestRate + .20;
    returnProductCosts[2] = dblDailyInterestRate + .19;
    returnProductCosts[3] = dblDailyInterestRate + .17;
    returnProductCosts[4] = dblDailyInterestRate + .16;
    returnProductCosts[5] = dblDailyInterestRate + .13;

    The elements in the array map to specific mortgage products; for example:

    • returnProductCosts[0] maps to a 30-year fixed mortgage product.

    • returnProductCosts[1] maps to a 15-year fixed mortgage product.

    • returnProductCosts[2] maps to a 3-year adjustable-rate mortgage (ARM) product.

    • returnProductCosts[3] maps to a 5-year ARM product.

    • returnProductCosts[4] maps to a 7-year ARM product.

    • returnProductCosts[5] maps to a 10-year ARM product.

    When you call the service later on, they way you use these different interest rates will become more apparent.

    At this point, you’ve created the code portion of your service. However, you’ll need to first amend the web.config file for service deployment, and then add a client access policy file to the service (so you can consume the service from a Microsoft Silverlight application).

    Note

    At the time of writing, it was necessary to amend the web.config file of the Windows Azure WCF service file. You can find more information on this hotfix here: http://code.msdn.microsoft.com/wcfazure/Wiki/View.aspx?title=KnownIssues. Check the Windows Azure team blog on a regular basis for any updates on this: http://blogs.msdn.com/b/windowsazure/.

  10. To amend the web.config file, double-click the file and then amend it as shown in the bolded code here—some of which has been removed for brevity:

    ...
    
    <system.serviceModel>
        <services>...
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="AzureMortgage.AzureService">
              <serviceMetadata httpGetEnabled="true" />
              <useRequestHeadersForMetadataAddress>
                <defaultPorts>
                  <add scheme="http" port="81" />
                  <add scheme="https" port="444" />
                </defaultPorts>
              </useRequestHeadersForMetadataAddress>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    
    ...
  11. You now need to add a client access policy file to complete the code portion of your service. To do this, right-click the project and select Add | New item.

  12. Select Data and then XML, call the file clientaccesspolicy.xml, and click Add.

  13. Copy and paste the following code into the file and save the file.

    <?xml version="1.0" encoding="utf-8"?>
    <access-policy>
      <cross-domain-access>
        <policy>
          <allow-from http-request-headers="*">
            <domain uri="*"/>
          </allow-from>
          <grant-to>
            <resource path="/" include-subpaths="true"/>
          </grant-to>
        </policy>
      </cross-domain-access>
    </access-policy>

    At this point, you’ve built the service and amended or added the necessary configuration files to support deploying the service to Windows Azure and to support cross-domain calls from a Silverlight application. What’s left now is to publish the service to Windows Azure.

  14. Press F6 to build the project, and make sure there are no build errors. Then right-click the cloud project and select Publish. This invokes the Deploy Windows Azure Project dialog box (see the following graphic), in which you can choose to create a service package or deploy your cloud service to Windows Azure (which requires some preconfiguration). Select Create Service Package Only.

    image with no caption
  15. Click OK. When Windows Explorer opens with the built and published files displayed, copy the folder path to the Clipboard.

  16. Open your Internet browser and navigate to your Windows Azure developer portal.

  17. Click Hosted Services in the main portal, and then select New Hosted Service.

  18. You’ll need to complete several fields for your service, as shown in the following graphic. For example, you’ll need to enter a name for your service, a unique URL to access your service, and a deployment name for your service. Also, select a region for your deployment (for example, Anywhere US) and a Deployment Option (for example, Deploy To Production Environment).

    image with no caption
  19. When you’ve completed these fields, you’ll then need to browse for the service package and configuration file for your service. Click Browse Locally, and then paste the folder path you copied earlier in the exercise. Add both the service package and the service configuration file.

  20. Click OK.

    Windows Azure will now deploy your WCF service for use with the hosted service you created in your Windows Azure account. This might take a few minutes to complete.

    image with no caption
  21. After the service web role has been created in the developer portal, the Status field will display the status as Ready.

  22. Click the new service, and then click the DNS name in the Properties pane.

    image with no caption
  23. Although your Internet browser will open, you will see an error page. This is because you need to append the URL with your service name to view the service’s Web Services Description Language (WSDL) definition page (for example, http://contosomortgage.cloudapp.net/AzureService.svc). Your service is now ready to be consumed from other applications.

    image with no caption

    If you’ve been following along, you have now completed the creation and deployment of a WCF service web role to Windows Azure. Congratulations! Although this service wasn’t extremely difficult code, the more important result here was that you now understand the process of how to create and publish the service to Windows Azure. You can tweak this service by editing the existing method, adding web methods, adding data constructs or connected entities, and more. And all you need to do each time is republish to Windows Azure to update the service as it exists in the cloud.

    Now that you’ve got the hang of WCF service web role deployment, let’s move on to building SharePoint applications that consume the WCF service.

 
Others
 
- Deploying Exchange Server 2010 : Integrating Exchange Server Roles with Active Directory
- Deploying Exchange Server 2010 : Exchange Server Messaging Roles
- SharePoint 2010: Performing Backups and Restores (part 3) - Example of Performing a SharePoint 2010 Farm Backup and Restore
- SharePoint 2010: Performing Backups and Restores (part 2) - Using STSADM
- SharePoint 2010: Performing Backups and Restores (part 1) - Using Windows PowerShell
- Microsoft Lync Server 2010 : Director Installation (part 2) - Install Server
- Microsoft Lync Server 2010 : Director Installation (part 1) - Prerequisites, Create Director Pool
- Microsoft Lync Server 2010 : Director Overview
- Configuring Windows Server 2008 Active Directory : Creating Objects in Active Directory (part 4) - Finding Objects by Using Dsquery
- Configuring Windows Server 2008 Active Directory : Creating Objects in Active Directory (part 3) - Finding Objects in Active Directory
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us