IT tutorials
 
Windows
 

Using the Windows Azure Service Bus with SharePoint (part 4) - Create a WCF Service to Call the On-Premises Service

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
11/21/2012 9:33:33 AM

Create a WCF Service to Call the On-Premises Service

To create the WCF service, you’ll use the Cloud template in Visual Studio 2010.

  1. Open the Visual Studio 2010 solution file you used in the previous exercise, right-click the solution, and select Add | New Project.

  2. Select the Cloud project template, provide a name for the service (such as SharePointCallingSvc), and then click OK.

  3. In the New Windows Azure Project dialog box, add the WCF Service Web Role to the Windows Azure Solution pane. You can opt to rename the WCF service by clicking the small edit icon.

  4. After adding the new project to the solution, rename the service and interface contracts from their default Service1 and IService1 to something more descriptive (such as SharePointCallingService and ISharePointCallingService).

  5. Right-click the project and select Add Reference. Click the Projects tab, and select Resources. You can also right-click the newly added project and select Project Dependencies to select Resources.

  6. Right-click the project and select Add Reference. Add a reference to the Microsoft.ServiceBus.dll to the project. Right-click the library after you add it to the project, and select Properties. Select True in the Copy To Local drop-down list.

  7. Right-click the project and select Add | New Item. In the Data category, select XML, and then name the file clientaccesspolicy.xml. You need to add this file when calling this service from Silverlight to enable cross-domain calls. Edit the clientaccesspolicy.xml file to match the XML code here:

    <?xml version="1.0" encoding="utf-8"?>
    <access-policy>
      <cross-domain-access>
        <policy>
          <allow-from http-request-headers="SOAPAction">
            <domain uri="*"/>
          </allow-from>
          <grant-to>
            <resource path="/"
                      include-subpaths="true"/>
          </grant-to>
        </policy>
      </cross-domain-access>
    </access-policy>
  8. Double-click the service interface file (for example, ISharePointCallingService.cs) and update the code in the interface file as shown in bold text here. This is the service contract code:

    using System;
    using System.Collections.Generic;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    
    namespace SharePointCallingSvc
    {
        [ServiceContract]
        public interface ISharePointCallingService
        {
            [OperationContract]
            List<Resources.Sales> GetSales();
        }
    
        public interface ICloudToSharePointChannel : ISharePointCallingService,
    IClientChannel { }
    }
  9. Double-click the main service file (for example, SharePointCallingService.cs) and edit the code to match the bold code here. This code is similar to the service you created earlier but is now implemented within the WCF Web Role template in a Windows Azure project:

    using System;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    using Resources;
    using System.Collections.Generic;
    using Microsoft.ServiceBus;
    
    namespace SharePointCallingSvc
    {
        [AspNetCompatibilityRequirements(RequirementsMode =
             AspNetCompatibilityRequirementsMode.Allowed)]
        public class SharePointCallingService : ISharePointCallingService
        {
            string svcNmspc = "servicebusexample";
            string svcBusName = "owner";
            string svcBusSecret = "<your secret here>";
            string svcName = "SPListenerService";
    
            public List<Sales> GetSales()
            {
                Uri svcURI = Microsoft.ServiceBus.ServiceBusEnvironment.
                    CreateServiceUri("sb", svcNmspc, svcName);
    
                TransportClientEndpointBehavior svcBusCreds = new
                    TransportClientEndpointBehavior();
                svcBusCreds.CredentialType = TransportClientCredentialType.SharedSecret;
                svcBusCreds.Credentials.SharedSecret.IssuerName = svcBusName;
                svcBusCreds.Credentials.SharedSecret.IssuerSecret = svcBusSecret;
    
                NetTcpRelayBinding binding = new NetTcpRelayBinding();
    
                ChannelFactory<ISalesDataChannel> channelFactory = new
                    ChannelFactory<ISalesDataChannel>(binding,
                    new EndpointAddress(svcURI));
                channelFactory.Endpoint.Behaviors.Add(svcBusCreds);
                ISalesDataChannel channel = channelFactory.CreateChannel();
    
                channel.Open();
                List<Sales> listFromOnPrem = channel.GetSales();
                channel.Close();
    
                return listFromOnPrem;
    
            }
        }
    }
  10. Finally, you’ll need to make sure that your DiagnosticsConnectionString is not configured to use your local development storage; you must edit these settings to deploy your service properly, as shown in the following code:

    <?xml version="1.0"?>
    <ServiceConfiguration serviceName="CloudService1" xmlns="http://schemas.microsoft.com/
    ServiceHosting/2008/10/ServiceConfiguration">
      <Role name="SharePointCallingSvc">
        <Instances count="2" />
        <ConfigurationSettings>
          <Setting name="DiagnosticsConnectionString"
            value="DefaultEndpointsProtocol=https;
            AccountName=<your cloud storage settings here e.g. servicebusexample> />
        </ConfigurationSettings>
      </Role>
    </ServiceConfiguration>

At this point, your Solution Explorer should look something like Figure 7. That is, you should have a Resources class library for your shared resources; a console application that is your local, on-premises service; and a WCF service (a WCF web role) that you’ll be deploying to Windows Azure.

The project files shown in the Solution Explorer.

Figure 7. The project files shown in the Solution Explorer.

You can now build and test your WCF service. An easy first test would be to deploy it to your local Internet Information Services (IIS) and test how the two services communicate with one another by using a simple Windows Forms test application. This is not necessary, but I’ve found that it saves time when debugging service code. You don’t need to change your code to do this. To deploy to your local IIS instance, create a folder on your local system (virtual directory), create a new IIS website, and then right-click the service project (for example, SharePointCallingSvc) and select Publish.

Note

Be sure not to select the Cloud project when publishing; you’ll do that when deploying to Windows Azure.

When you’re ready to publish your WCF service to Windows Azure, right-click the cloud project and select Publish. This will build and package your WCF service into a configuration file and a cloud package file. You’ve done this before, but the following steps provide a quick recap:

  1. Copy the directory path when Visual Studio opens Windows Explorer with the location of your two Cloud files.

  2. Navigate to your Windows Azure developer portal.

  3. Click Hosted Services, Storage Accounts & CDN. Click New Hosted Service in the New group on the ribbon.

  4. Provide a name for your service, a URL prefix, and the region to which you want to deploy the service. Select the Deploy To Production Environment check box, provide a deployment name, and then click Browse to navigate to the configuration file and cloud package file.

The WCF service should take a few minutes to upload and deploy correctly, and then you should be able to click the name of the service and in the DNS name find the main service namespace. Add the name of the service to your DNS name. You should now see something similar to Figure 8—the service definition page. Copy the service URI—you’ll use this in the next exercise.

The WCS service description page hosted in Windows Azure.

Figure 8. The WCS service description page hosted in Windows Azure.

At this point, you have an on-premises service that, when called, executes some code against SharePoint (specifically querying the SharePoint Sales list), and you have deployed a WCF service to Windows Azure that you can call from any application that is WCF conversant. When called, the WCF service initiates a connection to the service bus and then communicates with the on-premises service, which enables you to interact remotely with SharePoint.

 
Others
 
- Using the Windows Azure Service Bus with SharePoint (part 3) - Create an On-Premises Service
- Using the Windows Azure Service Bus with SharePoint (part 2) - Create the Listener Service
- Using the Windows Azure Service Bus with SharePoint (part 1) - Create a Service Bus Namespace
- Windows 8 : Working with User Accounts (part 3) - Switching Users
- Windows 8 : Working with User Accounts (part 2) - Changing User Account Settings
- Windows 8 : Working with User Accounts (part 1) - Add a User
- Mac OS X Hints
- Securing Your Windows 8 Computer : Maintaining Your Privacy
- Securing Your Windows 8 Computer : Switching to a Local Account
- Buyers' Guide : Mac Dreams (Part 3) - iPod classic, iPod Touch, iPod nano, iPod shuffle
 
 
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