consuming windows communication foundation services...

50
Hands-On Lab Consuming Windows Communication Foundation Services From SharePoint 2010 and InfoPath 2010 Lab version: 1.0.0 Last updated: 7/6/2022

Upload: lyque

Post on 29-Aug-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Hands-On LabConsuming Windows Communication Foundation Services From SharePoint 2010 and InfoPath 2010

Lab version: 1.0.0

Last updated: 5/10/2023

Page 2: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

CONTENTS

SECTION 1: CONSUMING A WINDOWS AZURE-HOSTED WCF SERVICE FROM SHAREPOINT.......4Overview 4

Exercise 1: Hosting a WCF Service in Windows Azure 5

Task 1 – Beginning the Exercise...........................................................................................................5

Task 2 – Implementing and Configuring the WCF Service....................................................................6

Task 3 – Adding a Cross-Domain Policy File.........................................................................................7

Task 4 – Publishing the WCF Service to Windows Azure.....................................................................8

Exercise 2: Create a Silverlight Application to Consume the WCF Service 14

Task 1 – Implementing the Silverlight Application.............................................................................14

Task 2 – Adding the SalarySLDisplay Silverlight Application to Your SharePoint Site.........................15

Summary 18

SECTION 2: CONSUMING AN ON-PREMISE WCF SERVICE FROM SHAREPOINT............................20Overview 20

Exercise 1: Create an On-Premise WCF Service 21

Task 1 – Beginning the Exercise.........................................................................................................21

Task 2 – Creating an XML File Containing Sample Data.....................................................................22

Task 3 – Creating and Configuring the EmployeeInfoSvc WCF Console Application..........................23

Exercise 2: Create a Windows Azure WCF Service to Forward Calls to the On-Premise Service 24

Task 1 – Creating the ForwarderServiceWebRole..............................................................................24

Exercise 3: Create a Silverlight Application to Consume the On-Premise WCF Service 26

Task 1 - Connecting the Silverlight Application to the CloudToOnPremForwarder Service...............26

Task 2 - Adding the Silverlight Application to your SharePoint Site...................................................27

Task 3 – Testing the End-to-End Solution..........................................................................................28

Summary 28

SECTION 3: CONSUMING A WINDOWS AZURE HOSTED SERVICE IN VIA SHAREPOINT LIST DATA ENTRY SCREEN (INFOPATH 2010).............................................................................................29

Overview 29

Exercise 1: Hosting a WCF Service in Windows Azure 30

Task 1 – Beginning the Exercise.........................................................................................................30

Task 2 – Implementing and Configuring the WCF Service..................................................................31

Task 3 – Publishing the WCF Service to Windows Azure....................................................................33

Page 3: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Exercise 2: Create a Custom List in SharePoint 33

Task 1 – Beginning the Exercise.........................................................................................................33

Exercise 3: Call Azure Service from List Data Entry screen 35

Pre-Requisites for this Exercise..........................................................................................................35

Task 1 – Creating a Data Connection Library.....................................................................................35

Task 2 – Customizing the Data Entry Screen......................................................................................35

Summary 42

Page 4: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Section 1: Consuming a Windows Azure-Hosted WCF Service from SharePoint

Overview

Silverlight Web Parts make it easy to interact with WCF services, including those hosted in Windows Azure, from SharePoint.

Objectives

In this lab, you will:

Create a simple WCF service and deploy it to Windows Azure.

Create a Silverlight application which consumes the WCF service and deploy it to a SharePoint site.

System Requirements

You must have the following items to complete this lab:

Windows Azure SDK and Windows Azure Tools for Microsoft Visual Studio (March 2011)

KB981002- WCF: Hotfix rollup in .NET 3.5 SP1 for Win 7 and Win 2k8 R2

Microsoft Silverlight 4 Tools for Visual Studio 2010

Silverlight 4 Developer Runtime

Access to a Windows Azure account.

Setup

The Windows Azure SDK (included in Windows Azure Tools for Visual Studio) installs a simulation environment on your development machine for testing Azure applications locally before deploying them to the cloud. The simulation environment consists of the development fabric to host web and worker roles, and the development storage which simulates cloud blob, table and queue storage locally.

Page 5: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Development storage uses SQL Server as its underlying storage mechanism, and by default the SDK will attempt to configure it to use SQL Server Express. If you do not have SQL Server Express installed before installing the SDK, or you wish to simply use an existing SQL Server instance to host the development storage database, you must run the dsinit command to select the SQL Server instance where the database will be created.

Please see instructions below for how to run dsinit.

Using dsinit to Configure Development Storage

1. Open a command prompt.

2. Edit the following command line as appropriate for your environment, where [AzureSDKInstallDrive] is the drive where you installed the Azure SDK (or Windows Azure Tools for Visual Studio), and [YourSqlInstance] is the SqlServer where you want to create the development storage database.

[AzureSDKInstallDrive]\ Program Files\Windows Azure SDK\v1.4\bin\devstore\dsinit.exe /sqlinstance:[YourSqlInstance].

Example Command Line:“C:\Program Files\Windows Azure SDK\v1.4\bin\devstore\dsinit.exe” /sqlinstance:.

3. Note that the sample command line above uses the value “.” for the sqlinstance argument, which specifies that the local default SQL instance will be used for development storage.

Estimated time to complete this lab: 20 minutes

Exercise 1: Hosting a WCF Service in Windows Azure

Task 1 – Beginning the Exercise

In this task, you will open the lab solution in Visual Studio 2010.

1. Make sure that you’ve downloaded and installed the items listed in System Requirements above prior to beginning this exercise.

2. Launch Visual Studio 2010 as administrator and open the lab project by selecting File » Open » Project.

a. Browse to the SPToWinAzureWCF.sln file located at Before folder of this lab and select it.

Page 6: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

b. Click Open to open the solution.

Task 2 – Implementing and Configuring the WCF Service

In this task, you will implement a service operation on the SalaryService WCF service, and modify the web.config file to configure WCF hosting for the service.

1. In the SalaryServiceWebRole project, open the file SalaryService.svc.cs.

2. Add the following code under the //TODO: 5.1.1 comment to define the SalaryService class and it’s AdjustSalaryForInflation method:

C#

[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)][AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class SalaryService : SalaryServiceWebRole.ISalaryService { public double AdjustSalaryForInflation(double startingSalary, double inflationPercent) { double newSalary = startingSalary * (1 + inflationPercent / 100); return newSalary; } }

3. The above code performs a simple calculation to determine what salary adjustment should be made given a starting salary and an annual inflation percentage. The ServiceBehavior attribute ensures that client requests from any address are accepted. The AspNetCompatibilityRequirements attributed is needed to ensure compatibility with Silverlight.

4. Open the Web.Config file.

5. Add the following to the System.ServiceModel section to configure hosting of the WCF service, under the //TODO: 5.1.2 comment:

XML

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> <services> <service behaviorConfiguration="SalaryServiceWebRole.CloudWCFServiceBehavior"

Page 7: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

name="SalaryServiceWebRole.SalaryService"> <endpoint address="" binding="basicHttpBinding" contract="SalaryServiceWebRole.ISalaryService" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="SalaryServiceWebRole.CloudWCFServiceBehavior"> <!--The useRequestHeadersForMetadataAddress behavior is contained in the KB981002- WCF: Hotfix rollup upodate. This behavior is required for WCF to correctly serve metadata when behind a load balancer (which is the case in Windows Azure)--> <useRequestHeadersForMetadataAddress> <defaultPorts> <add scheme="http" port="81"/> <add scheme="https" port="444"/> </defaultPorts> </useRequestHeadersForMetadataAddress> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors>

About the System.ServiceModel configuration above:

For this example we are exposing a metadata exchange (MEX) endpoint in addition to the service main endpoint. This will expose the service metadata and thus allow service references to be added to this service in Visual Studio.

The useRequestHeadersForMetadataAddress behavior is a special behavior that is defined in KB981002- WCF: Hotfix rollup update. It allows WCF to serve correct metadata behind load balancers. Windows Azure web roles are load balanced between one or more physical servers.

Task 3 – Adding a Cross-Domain Policy File

In this task, you will create a client access policy file to allow Silverlight clients to make cross-domain calls to the WCF service. Any Silverlight-enabled WCF service which must allow Silverlight clients to consume it from outside of the domain where the WCF service is hosted must have this file exposed at the root level of its address.

Page 8: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

1. Right-click the SalaryServiceWebRole project, and choose Add » New Item.

2. In the Installed Templates pane of the Add New Item dialog, select Data.

3. Choose the XML File template.

4. Name the file clientaccesspolicy.xml and click Add. The new XML file will open in Visual Studio.

5. Add the following under the XML declaration tag:

XML

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

The above clientaccesspolicy.xml file allows access by callers from any domain to any path within the root URL where the WCF service is hosted. In a production scenario, the allow-from domain and grant-to paths would likely be much more restrictive.

6. Set the SalaryService.svc as start up page and Demo51CloudApp as start up project. Run Demo51CloudApp project in the local simulation environment by hitting the F5 key. This causes the web roles to run on your local machine.

Task 4 – Publishing the WCF Service to Windows Azure

In this task, you will publish the SalaryService to you Windows Azure account.

1. Clean and Build the SalaryServiceWebRole.

2. Clean and Build the Demo51CloudApp solution.

3. Right-click on the Demo51CloudApp, and select Publish.

4. There are two ways to publish the service to Windows Azure.

a. Create a service package, uploading it to Windows Azure.

Page 9: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

b. Directly deploying to Windows Azure.

In this case, we’ll be creating the service package and upload it to Windows Azure. To do so, select the Create Service Package Only option in the Publish dialog box, and select OK.

Figure 1Publish dialog box

5. The service package will now be created in a folder named Publish inside the bin directory. You can access it under the following folder of this lab:\Source\Sec1 -AzureFromSPOnPrem\Before\Demo51CloudApp\bin\Debug\Publish\

Two files are created at the above location. – The service package file (.cspkg) and the service configuration file (.cscfg)

6. The next step is to upload the published files to windows azure and activate them. To do so, Open Internet Explorer, and go to http://windows.azure.com. Login with your Azure credentials. If you do not have a Windows Azure Account, sign-up for a new one.

7. Create a new Hosted service by clicking the New Hosted Service from the ribbon menu.

Page 10: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Figure 2Ribbon menu

8. Configure the new service as follows:

a. Choose a subscription: Select the name of Azure subscription. (You would have provided this information while signing up for Azure account.)

b. Name of the Service: Provide a user friendly name to the service.

c. URL prefix of your service: This is a unique URL. Choose an URL that is available. Note: When you delete this service, the URL is immediately available to others.

d. Region or Affinity group: This is the physical location of the Azure datacenter hosting your service. Choose a region.

e. Deployment Options: Select “Deploy to stage environment”. It is possible to directly publish the service to a production environment also. But as a best practice, publish the service to a staging environment, and test it on staging before publishing it to Production.

f. Deployment Name: A user friendly name that helps to identify this service.

g. Package Location: Select “Browse Locally”, and browse to the .cspkg file that you published earlier and select the file.

h. Configuration file: Select “Browse Locally, and browse to the.cscfg file that you published earlier and select the file.

Page 11: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

i. Click OK to complete creating the new hosted service.

Figure 3New Hosted Service Dialog

9. If you see a warning, click Yes to override and submit. This is a warning that this deployment is a single instance deployment. For a 99.95% uptime Microsoft recommends at least 2 instances. You can always increase the number of instances in the Production deployment by changing it in the configuration file

Figure 4

Page 12: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Warning

10. It could take a few minutes for the staging environment to be ready. The image below shows a Staging environment when ready.

Figure 5Staging environment

The DNS name on the right panel is the staging URL

11. Next , publish the service to production. To do this, first select the service deployed to Windows Azure. Then, from the ribbon menu, select Swap VIP.

Figure 6Ribbon menu

12. Click OK to swap the bits deployed in Staging with the bits in production.

Note: If the production slot is not empty, the contents of the production will be moved to Staging.

Page 13: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Figure 7Swap VIPs

Once deployed to production, test the service from Internet Explorer by navigating to the path where the service is deployed.

Figure 8Internet Explorer

Page 14: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Exercise 2: Create a Silverlight Application to Consume the WCF Service

Task 1 – Implementing the Silverlight Application

In this exercise you will create a Silverlight application to invoke the WCF service.

1. Expand the SalarySLDisplay project in Solution Explorer.

2. Right click References and select Add Service Reference.

3. Enter the URL for your service in Azure. For example,http://mysalaryservice001.cloudapp.net/SalaryService.svc

4. Click Go.

5. For the Namespace, enter SalaryService.

6. Click OK to generate the proxy classes and configuration.

Figure 9Add Service Reference Dialog

7. Open the MainPage.xaml.cs file.

8. Add the following code to the Button_Click method, after the //TODO: 5.1.4 comment.

Page 15: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

C#

SalaryServiceClient client = new SalaryServiceClient();client.AdjustSalaryForInflationCompleted += new EventHandler<AdjustSalaryForInflationCompletedEventArgs>(client_AdjustSalaryForInflationCompleted);client.AdjustSalaryForInflationAsync(double.Parse(txtCurrentSalary.Text), double.Parse(txtInflationPercent.Text));

The above code creates an instance of the SalaryService proxy, and initiates an asynchronous call to the AdjustSalaryForInflation method. Silverlight only allows async calls to WCF services (to avoid tying up the main UI thread and hence hanging the UI), so when a service reference is added to a Silverlight project, the given async operation equivalent and completion events are automatically added to the proxy class.

9. Add the following method to the MainPage class, after the //TODO: 5.1.5 comment.

C#

void client_AdjustSalaryForInflationCompleted(object sender, AdjustSalaryForInflationCompletedEventArgs e){ if (e.Error == null) { this.lblNewSalary.Content = string.Format("{0:C}", e.Result); this.Storyboard1.Begin(); } else { MessageBox.Show("An error occurred: \r\n\r\n" + e.Error.Message); }}

The above method executes when the call to the AdjustSalaryForInflation WCF service call completes. While the service call is executed on a background thread, the completion handler is invoked on the UI thread, which is the only thread from which UI updates are permitted.

10. Right click the SalarySLDisplay project and select Build.

Task 2 – Adding the SalarySLDisplay Silverlight Application to Your SharePoint Site

In this task, you will upload the SalarySLDisplay Silverlight application to SharePoint Portal, and display it in a web part.

1. Log into your SharePoint site.

Page 16: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

2. If you do not already have a document library created for storage of Silverlight XAP files, create one now:

a. In the Site Actions menu, click New Document Library.

b. In the Name field, type Silverlight Apps.

c. In the Document Template field, select None.

d. Click Create.

3. Navigate to your Silverlight Applications document library if necessary.

4. Click Add document.

5. Click Browse.

6. Navigate to the bin\debug directory within the SalarySLDisplay project.

7. Select the file SalarySLDisplay.xap.

8. Click Open.

9. Click OK.

10. An entry in the document library appears for SalarySLDisplay.

11. Right click the SalarySLDisplay entry’s Name column and select Copy Shortcut.

12. Navigate to the Home page in your SharePoint site.

13. In the Site Actions menu, click Edit Page.

14. Under the Editing Tools menu, click Insert.

15. In the Insert ribbon, click Web Part.

16. Under Filter By, choose Media and Content.

17. Select the Silverlight Web Part, and click Add.

18. Paste the URL for the XAP file (copied to clipboard in step 11 above) into the URL box and click OK.

19. If necessary, resize the Silverlight Web Part to center contents. This can be done by clicking the down arrow above the Web Part and clicking Edit Web Part. The tool pane will open on the right side of the screen and a new width and height can be entered. Click OK in the toolpane to apply the changes.

20. When the Silverlight web part is displayed on the page, enter a Current Salary and Annual Inflation Percent into the text boxes.

21. Click Get Adjusted Salary to test consuming the WCF service.

22. You may see a popup window appear which asks you if you want to Display Mixed Content.

Page 17: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Figure 10Pop-up window

23. If you see this pop click Yes.

24. To prevent the popup from displaying in the future in Internet Explorer click Tools and select Options.

25. Select the Security tab.

26. Click Custom Level.27. Located Display mixed content and select Enable.

Page 18: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Figure 11Security settings

28. Click OK.

29. Click Yes.

30. Click OK.

Summary

Consuming Windows Azure-Hosted WCF services from SharePoint is easily accomplished via a Silverlight application running in a Silverlight Web Part. In fact, from the perspective of SharePoint and Silverlight it is no different from consuming a WCF service which is not hosted in Windows Azure. In this lab, you learned how to create a basic WCF service in a Windows Azure web role. You also learned how to create a cross-domain policy file which enables Silverlight applications to call outside of the site in which they’re deployed, enabling access to cloud services. Finally, you learned how to reference a WCF service

Page 19: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

in the cloud from a Silverlight application, and display that application in a Silverlight web part in SharePoint.

Page 20: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Section 2: Consuming an On-Premise WCF Service from SharePoint

Overview

Silverlight Web Parts and the Azure AppFabric Service Bus make it easy to interact with on-premise WCF services hosted inside your protected intranet from SharePoint. “On-Premise” means any internal WCF service which runs within the confines of a corporate intranet, or otherwise within the bounds of a server which is protected by firewalls /network address translation (NAT) and which has no public IP or direct exposure to the internet.

Objectives

In this lab, you will:

Create a simple WCF service hosted in a console application.

Create a WCF “forwarder” service hosted in Windows Azure which will forward calls to the console WCF service via the Azure AppFabric Service Bus.

Create a Silverlight application which consumes the on-premise console WCF service via routing a call through the forwarder service.

System Requirements

You must have the following items to complete this lab:

Windows Azure SDK and Windows Azure Tools for Microsoft Visual Studio (March 2011)

KB981002- WCF: Hotfix rollup in .NET 3.5 SP1 for Win 7 and Win 2k8 R2

Microsoft Silverlight 4 Tools for Visual Studio 2010

Silverlight 4 Developer Runtime

Access to a Windows Azure account.

Page 21: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Setup

The Windows Azure SDK (included in Windows Azure Tools for Visual Studio) installs a simulation environment on your development machine for testing Azure applications locally before deploying them to the cloud. The simulation environment consists of the development fabric to host web and worker roles, and the development storage which simulates cloud blob, table and queue storage locally.

Development storage uses SQL Server as its underlying storage mechanism, and by default the SDK will attempt to configure it to use SQL Server Express. If you do not have SQL Server Express installed before installing the SDK, or you wish to simply use an existing SQL Server instance to host the development storage database, you must run the dsinit command to select the SQL Server instance where the database will be created.

Please see instructions below for how to run dsinit.

Using dsinit to Configure Development Storage

1. Open a command prompt.

2. Edit the following command line as appropriate for your environment, where [AzureSDKInstallDrive] is the drive where you installed the Azure SDK (or Windows Azure Tools for Visual Studio), and [YourSqlInstance] is the SqlServer where you want to create the development storage database.

[AzureSDKInstallDrive]\ Program Files\Windows Azure SDK\v1.4\bin\devstore\dsinit.exe /sqlinstance:[YourSqlInstance].

Example Command Line:“C:\Program Files\Windows Azure SDK\v1.4\bin\devstore\dsinit.exe” /sqlinstance:.

3. Note that the sample command line above uses the value “.” for the sqlinstance argument, which specifies that the local default SQL instance will be used for development storage.

Estimated time to complete this lab: 20 minutes

Exercise 1: Create an On-Premise WCF Service

In this exercise, you will create an On-Premise WCF service hosted in a console application.

Task 1 – Beginning the Exercise

In this task, you will open the lab solution in Visual Studio 2010.

Page 22: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

1. Make sure that you’ve downloaded and installed the items listed in System Requirements above prior to beginning this exercise.

2. Launch Visual Studio 2010 and open the lab project by selecting File » Open » Project.

a. Browse to the SPtoOnPremise.sln file located at the Before folder of the lab.

b. Click Open to open the solution.

Task 2 – Creating an XML File Containing Sample Data

In this task, you will create an XML file which contains data that will be returned by the on-premise WCF service to client applications.

1. Right-click the EmployeeInfoService project, and choose Add » New Item.

2. In the Installed Templates pane of the Add New Item dialog, select Data.

3. Choose the XML File template.

4. Name the file EmployeeList.xml and click Add. The new XML file will open in Visual Studio.

5. Replace the default contents of the file with the following XML:

XML

<?xml version="1.0"?><ArrayOfEmployee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Employee> <FirstName>Ted</FirstName> <LastName>Burgundy</LastName> <Salary>89000</Salary> </Employee> <Employee> <FirstName>Jane</FirstName> <LastName>Smith</LastName> <Salary>72000</Salary> </Employee> <Employee> <FirstName>Rita</FirstName> <LastName>Flores</LastName> <Salary>115000</Salary> </Employee> <Employee> <FirstName>Bob</FirstName> <LastName>Hess</LastName> <Salary>82000</Salary> </Employee> <Employee> <FirstName>Allen</FirstName>

Page 23: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

<LastName>Jackson</LastName> <Salary>91000</Salary> </Employee></ArrayOfEmployee>

6. Right-click the EmployeeList.xml file and choose Properties. In the Copy to Output Directory property, choose Copy Always.

Task 3 – Creating and Configuring the EmployeeInfoSvc WCF Console Application

In this task, you will implement a service operation on the EmployeeInfoSvc WCF service, and modify the web.config file to configure expose a service endpoint via the Azure AppFabric Service bus.

1. In the EmployeeInfoService project, open the file EmployeeInfoSvc.cs. Insert the following code in the EmployeeInfoSvc class, under the //TODO:5.2.2 comment:

C#

List<Employee> IEmployeeInfoSvc.GetEmployees(){ Console.WriteLine("GetEmployees was called.");

XmlSerializer xs = new XmlSerializer(typeof(List<Employee>)); object employeeList = null; using (FileStream fs = new FileStream("EmployeeList.xml", FileMode.Open)){ employeeList = xs.Deserialize(fs);} return (List<Employee>)employeeList;}

2. The above code deserializes the EmployeeList.xml file into a generic List of Employee objects, and returns that list to the caller.

3. Open the Program.cs file.

4. Add the following code to the Main() method, under the //TODO: 5.2.3 comment.

C#

_wcfHost = new ServiceHost(typeof(EmployeeInfoSvc));

Page 24: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

_wcfHost.Open();

Console.WriteLine("Employee info service is running.");Console.WriteLine("Press [Enter] to exit...");Console.ReadLine();

_wcfHost.Close();

The above code creates a WCF service hosting environment and instructs it to expose the EmployeeInfoSvc type as a service. This means that instsances of EmployeeInfoSvc will be created to serve incoming requests. Requests are served on background threads.

Specifics of how the WCF service is hosted are contained in the app.config file. This service opens a relayed TCP (binary) endpoint in the Azure AppFabric service bus, allowing it to receive requests from the internet without being directly exposed to the internet. This is possible because the service’s binding, netTcpRelayBinding, initiates an outbound, bi-directional TCP channel, allowing it to traverse network address translation (NAT) and firewalls. For more information on the AppFabric service bus, see Getting Started with AppFabric Service Bus.

5. To create a new service namespace, log on to Windows Azure Appfabric portal at http://appfabric.azure.com using your azure credentials.

6. Create a new service namespace.

7. Back in your EmployeeInfoService project, Open the app.config file .

8. Replace the text [YourServiceBusNamespace] with a service bus namespace from your Azure AppFabric account.

9. Replace the text [YourIssuerName] and [YourIssuerSecret] with valid values for your Azure AppFabric account.

10. Build the EmployeeInfoService Project.

Exercise 2: Create a Windows Azure WCF Service to Forward Calls to the On-Premise Service

In this exercise, you will create a WCF service which will be hosted in Windows Azure. This service will receive calls from a Silverlight Web Part running in SharePoint and forward them to the EmployeeInfoSvc on-premise WCF service, via the Azure AppFabric service bus.

**Note that this exercise is only necessary because version 1.0 of the Azure AppFabric Service Bus does not support Silverlight clients directly. This capability will be introduced in the upcoming AppFabric version and will eliminate the need to forward calls through Windows Azure in this scenario.

Task 1 – Creating the ForwarderServiceWebRole.

1. Open the CloudToOnPremForwarder.svc.cs file in the ForwarderServiceWebRole project.

Page 25: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

2. Replace the text [YourServiceBusNamespace] with the service bus namespace from your Azure AppFabric account which you used for the console application above.

3. Replace the text [YourIssuerName] and [YourIssuerSecret] with the service bus issuer name and secret from your Azure AppFabric account which you used for the console application above.

4. Add the following code to the GetEmployees(), after the //TODO:5.2.4 comment.

C#

Uri serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, serviceName);

// create the credentials object for the endpointTransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior();sharedSecretServiceBusCredential.CredentialType = TransportClientCredentialType.SharedSecret;sharedSecretServiceBusCredential.Credentials.SharedSecret.IssuerName = issuerName;sharedSecretServiceBusCredential.Credentials.SharedSecret.IssuerSecret = issuerSecret;

NetTcpRelayBinding binding = new NetTcpRelayBinding();

// create the channel factory loading the configurationChannelFactory<IEmployeeInfoChannel> channelFactory = new ChannelFactory<IEmployeeInfoChannel>(binding, new EndpointAddress(serviceUri));

// apply the Service Bus credentialschannelFactory.Endpoint.Behaviors.Add(sharedSecretServiceBusCredential);

// create and open the client channelIEmployeeInfoChannel channel = channelFactory.CreateChannel();channel.Open();

List<Employee> listFromOnPrem = channel.GetEmployees();

channel.Close();

return listFromOnPrem;

The above code creates a client endpoint in the AppFabric Service Bus which maps to the endpoint created by the console application in the previous exercise. Any .NET application with access to the internet and the proper service bus credentials is able to consume the console

Page 26: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

application’s WCF service.

Note that the WCF client code above does not need to use design time generated proxies, meaning there is no service reference present. Instead, the client and service applications share a reference to a common assembly (Shared.dll, defined in the Shared project of this solution) which contains the service and operation contracts. The ChannelFactory is used to create a runtime proxy based on the shared assembly. In general, this technique is the most efficient choice when both the client and service application are controlled by the same development team and there is no nead to expose the service to external parties.

Note: Microsoft.ServiceBus.dll is not installed on Azure boxes. In the WebRole project, the reference Microsoft.ServiceBus.dll is configured for "Copy Local = True". This causes the assembly Microsoft.ServiceBus.dll to be packaged up with your WebRole project, before it is deployed to Azure. This is a mandatory step, otherwise the WebRole will fail to run on the cloud.

5. Set the CloudToOnPremForwarder.svc as start up page and Demo52CloudApp as start up project. Run Demo52CloudApp project in the local simulation environment by hitting the F5 key. This causes the web roles to run on your local machine.

6. Build the Solution and publish the Demo52CloudApp project to your Windows Azure account by right-clicking on the Demo52CloudApp project and selecting Publish. Follow the instructions in Lab 1 to publish the service to Azure.

7. Browse to the service information page to verify that CloudToOnPremForwarder service is active. For example, http://myaccount.cloudapp.net/CloudToOnPremForwarder.svc.

Exercise 3: Create a Silverlight Application to Consume the On-Premise WCF Service

Task 1 - Connecting the Silverlight Application to the CloudToOnPremForwarder Service

In this task, you will update the ServiceReferences.ClientConfig file of the EmployeeInfoSLDisplay project.

1. Open the ServiceReferences.ClientConfig file in the EmployeeInfoSLDisplay project.

2. Replace the text [YourCloudServiceAddress] with the address of the service you deployed to Windows Azure in previous steps. For example, http://myaccount.cloudapp.net/CloudToOnPremForwarder.svc

3. Right-click on the EmployeeSLDisplay project and select Build to build the Silverlight application.

Page 27: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Task 2 - Adding the Silverlight Application to your SharePoint Site

In this task, you will upload the SalarySLDisplay Silverlight application to SharePoint, and display it in a web part.

1. Log into a your SharePoint site.

2. If you do not already have a document library created for storage of Silverlight XAP files, create one now:

a. In the Site Actions menu, click New Document Library.

b. In the Name field, type Silverlight Apps.

c. In the Document Template field, select None.

d. Click Create.

3. Navigate to your Silverlight Applications document library if necessary.

4. Click Add Document.

5. Click Browse.

6. Navigate to the bin\debug directory within the EmployeeInfoSLDisplay project.

7. Select the file EmployeeInfoSLDisplay.xap.

8. Click Open.

9. Click OK.

10. An entry in the document library appears for EmployeeInfoSLDisplay.

11. Right click the entry’s Name column and select Copy Shortcut.

12. Navigate to the Home page in your Sharepoint site in which you want to display the Silverlight application.

13. In the Site Actions menu, click Edit Page.

14. Under the Editing Tools menu, click Insert.

15. In the Insert ribbon, click Web Part.

16. Under Filter By, choose Media and Content.

17. Select the Silverlight Web Part, and click Add.

18. Paste the URL for the XAP file (copied to clipboard in step 11 above) into the URL box and click OK.

19. If necessary, resize the Silverlight Web Part to center contents. This can be done by clicking the down arrow above the Web Part and clicking Edit Web Part. The tool pane will open on

Page 28: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

the right side of the screen and a new width and height can be entered. Click OK in the toolpane to apply the changes.

Task 3 – Testing the End-to-End Solution

1. Start the EmployeeInfoService console application by right clicking the project in Visual Studio and selecting Debug » Start New Instance.

a. Wait for "Press [Enter] to exit..." to be written to the console.

2. On the SharePoint page where you’ve hosted the EmployeeInfo Silverlight application, click the Get Employees button.

Silverlight will call into your console application via Windows Azure and the .NET service bus, and display the list of employees in the data grid.

Summary

Consuming on-premise WCF services from SharePoint is easily accomplished via a Silverlight application running in a Silverlight Web Part. The chief mechanism which allows SharePoint to communicate with back-end systems protected by firewalls is the Azure AppFabric Service bus.

In this lab, you learned how to create a basic WCF service in a console application, and expose an endpoint for that service in the AppFabric service bus. You also learned how to consume data returned by that service with a Silverlight Application hosted in SharePoint.

Page 29: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Section 3: Consuming a Windows Azure hosted Service in via SharePoint List Data Entry Screen (InfoPath 2010)

Overview

InfoPath 2010 allows users to quickly design forms with easy-to-use tools. Users can build advanced forms and connect them to line-of-business systems. With Microsoft InfoPath 2010, you can customize the forms used for creating and editing items in a SharePoint list. By using the Data Connections capability of InfoPath, users can add data retrieval capabilities to a SharePoint list.

Objectives

In this lab, you will:

Create a custom list in a SharePoint site to hold inventory replenishment requests which are created by a Windows Azure worker role.

Create a simple WCF service that returns a Credit Score for a given Social Security Number.

Deploy the Credit Score service to Windows Azure.

Create a customer list in a SharePoint site to hold customer loan requests.

Customize the SharePoint list data entry screen (InfoPath 2010) to include calls to Azure service.

Configure a Loan Approval workflow on the SharePoint list.

System Requirements

You must have the following items to complete this lab:

Windows Azure SDK and Windows Azure Tools for Microsoft Visual Studio (November 2010)

KB981002- WCF: Hotfix rollup in .NET 3.5 SP1 for Win 7 and Win 2k8 R2

Silverlight 4 Developer Runtime

Access to a Windows Azure account.

Page 30: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

InfoPath 2010 designer.

Setup

The Windows Azure SDK (included in Windows Azure Tools for Visual Studio) installs a simulation environment on your development machine for testing Azure applications locally before deploying them to the cloud. The simulation environment consists of the development fabric to host web and worker roles, and the development storage which simulates cloud blob, table and queue storage locally.

Development storage uses SQL Server as its underlying storage mechanism, and by default the SDK will attempt to configure it to use SQL Server Express. If you do not have SQL Server Express installed before installing the SDK, or you wish to simply use an existing SQL Server instance to host the development storage database, you must run the dsinit command to select the SQL Server instance where the database will be created.

Please see instructions below for how to run dsinit.

Using dsinit to Configure Development Storage

1. Open a command prompt.

2. Edit the following command line as appropriate for your environment, where [AzureSDKInstallDrive] is the drive where you installed the Azure SDK (or Windows Azure Tools for Visual Studio), and [YourSqlInstance] is the SqlServer where you want to create the development storage database.

[AzureSDKInstallDrive]\ Program Files\Windows Azure SDK\v1.4\bin\devstore\dsinit.exe /sqlinstance:[YourSqlInstance].

Example Command Line:“C:\Program Files\Windows Azure SDK\v1.4\bin\devstore\dsinit.exe” /sqlinstance:.

3. Note that the sample command line above uses the value “.” for the sqlinstance argument, which specifies that the local default SQL instance will be used for development storage.

Estimated time to complete this lab: 20 minutes

Exercise 1: Hosting a WCF Service in Windows Azure

Task 1 – Beginning the Exercise

In this task, you will open the lab solution in Visual Studio 2010.

Page 31: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

1. Make sure that you’ve downloaded and installed the items listed in System Requirements above prior to beginning this exercise.

2. Launch Visual Studio 2010 as administrator and open the lab project by selecting File » Open » Project.

a. Browse to the SPInfoPathAzure.sln file located at the Before folder of the lab.

b. Click Open to open the solution.

Task 2 – Implementing and Configuring the WCF Service

In this task, you will implement a service operation on the Credit Score WCF service, and modify the web.config file to configure WCF hosting for the service.

1. In the CreditScoreWebRole project, open the file CreditScoreService.svc.cs.

2. Add the following code under the //TODO: 5.4.1 comment to define the CreditScoreService class and it’s GetCreditScore method:

C#

[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class CreditScoreService : ICreditScoreService { public int GetCreditScore(string SSNumber) { try { int CreditScore = default(int);

// This block should ideally fetch the credit scrore for the given SSN // However, in this case, we'll generate a random score

Random random = new Random(); CreditScore = random.Next(550, 800);

return CreditScore; } catch (Exception ex) { return 0; } } }

Page 32: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

The above code simple returns a random number between 550 and 800. Ideally, in the real world scenario, this method will return the credit score for the given SSN#.

3. Open the Web.Config file.

4. Add the following to the System.ServiceModel section to configure hosting of the WCF service, under the //TODO: 5.4.2 comment:

XML

<behaviors> <serviceBehaviors> <behavior name="CreditScoreWebRole.CreditScoreBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" />

<useRequestHeadersForMetadataAddress> <defaultPorts> <add scheme="http" port="81" /> <add scheme="https" port="444" /> </defaultPorts> </useRequestHeadersForMetadataAddress> </behavior> </serviceBehaviors></behaviors><services> <service behaviorConfiguration="CreditScoreWebRole.CreditScoreBehavior" name="CreditScoreWebRole.CreditScoreService"> <endpoint address="" binding="basicHttpBinding" contract="CreditScoreWebRole.ICreditScoreService"> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service></services>

About the System.ServiceModel configuration above:

For this example we are exposing a metadata exchange (MEX) endpoint in addition to the service main endpoint. This will expose the service metadata and thus allow service references to be added to this service in Visual Studio.

Page 33: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

The useRequestHeadersForMetadataAddress behavior is a special behavior that is defined in KB981002- WCF: Hotfix rollup upodate. It allows WCF to serve correct metadata behind load balancers. Windows Azure web roles are load balanced between one or more physical servers.

5. Set CreditScoreService.svc as start up page and Demo54CloudApp as start up project. Run Demo54CloudApp project in the local simulation environment by hitting the F5 key. This causes the web roles to run on your local machine and tests the service to make sure it is ready for deployment to the cloud.

Task 3 – Publishing the WCF Service to Windows Azure

1. Follow the instructions in Lab 1, Exercise 1 to publish this to Azure as a new hosted service.

Exercise 2: Create a Custom List in SharePoint

In this exercise, you will create a custom list in your SharePoint site for storing the customer information and their loan requests.

Task 1 – Beginning the Exercise

1. The SharePoint list to be used with this exercise, along with the customized data entry InfoPath form is packaged as a .stp file and located at the Before folder of the lab.

2. Login to a SharePoint site collection.

3. Navigate to the Site Settings page.

4. Under Galleries, select List Templates.

5. Click Documents in the ribbon.

6. Click Upload Document.

7. Browse to the customers.stp file and select it.

8. Click Open.

9. Click OK.

10. Click Save

11. Creating a new list from the template

a. Go to the SharePoint site of your choice.

b. Click All Site Content.

c. Click Create.

d. Select the customers template from the list of available list templates.

e. In the Name textbox enter Customers.

Page 34: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

f. Click Create.

The Customers list is now ready to be used.

12. Configuring Worklfow

a. From the Ribbon menu, choose List tools.

b. Under List click Workflow Settings.

c. Click Add a workflow.

d. From the list of available templates, choose the Approval – SharePoint 2010 out-of-box workflow.

e. In the Name textbox enter Loan Request Approval.

f. Check Start this workflow when the new item is created.

g. Click Next.

h. In the next screen specify other workflow settings like Assigned to (Approver), Due Date and Duration.

i. Click Save to complete configuring the workflow.

13. Navigate to the Customers list, and select Add a new Item. The List entry screen should look as follows:

Figure 1Customers New Item Dialog

Page 35: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

14. Close the form.

Exercise 3: Call Azure Service from List Data Entry screen

In this exercise, you will customize the List data entry screen to call the Azure service that you created in exercise 1. When the form is submitted, before the data is actually inserted into the list, a call to Azure service returns the credit score of the customer. The credit score along with other user entered information is inserted into the list.

Pre-Requisites for this Exercise

1. SharePoint 2010 Enterprise is required for enable data connection from InfoPath forms to Azure service.

2. Ensure that the Enterprise features and other required settings are enabled.

a. Go to SharePoint central administration, Under “Upgrade and Migration” select “Enable Enterprise Features”. Enable the enterprise features if not already enabled.

b. From the Central administration, Under System Settings select Manage Farm Features. Ensure “Data Connection Library” Feature is enabled.

c. From the Central Administration, Under “General Application settings” select “Configure InfoPath Forms Services”. Check the “Allow Cross domain data access from user form templates” option.

d. Navigate to the Site Collection where the customers list is created. From Site Settings under Site Collection Administration, Activate “SharePoint Server Enterprise Site Collection Features” (if not already activated).

Task 1 – Creating a Data Connection Library

The Data Connection Library (DCL) is a kind of document library in Microsoft SharePoint Server 2010 that enables applications such as Microsoft InfoPath 2010 and technologies such as Excel Services to specify data connection settings using external files. For more about Data Connection libraries refer to: http://msdn.microsoft.com/en-us/library/ms772364.aspx

1. Create a new Data Connection library

a. Click All Site Content, then click Create. Using the Data Connection Library template create a new Data connection library. Give this library a name - Data Connections.

Page 36: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Task 2 – Customizing the Data Entry Screen

1. Navigate to the Customers list.

2. From the ribbon, under List Tools, select List.

3. Click Customize Form.

4. The InfoPath form will open in edit mode in InfoPath Designer 2010.

5. Configuring the Data Connection to the Azure service.

a. On the Data tab from the ribbon menu, click Data Connections, and then click Add.

b. In the Data Connection Wizard, click Create a new connection to, click Receive data, and then click Next.

c. Select SOAP Web Service as the kind of data source that you are connecting to, then click Next.

d. Enter the location of the Credit Score WCF Service that you had published in the exercise 1 of this lab and add the ?WSDL querystring.(Ex: http://yourservice.cloudapp.net/CreditScoreService.svc?WSDL)Click Next to continue.

e. The next screen will show the list of operations available via the service. In this case, you’ll have only Operation – GetCreditScore. Select the operation and then click Next.

f. In the next screen accept the default value (empty) for tns:SSNumber. Click Next

g. Leave the check box - Store a copy of the data in the form template as Unchecked. Click Next.

h. Type GetCreditScore for the name of this data connection. Check Automatically retrieve data when the form is opened. Click Finish to return to the Data Connections dialog box.

i. In the Data Connections dialog box, click Convert to Connection File.

j. In the Convert Data Connection dialog box, enter the URL of the data connection library that you previously copied (delete "Forms/AllItems.aspx" and anything following it from the URL), enter a name for the data connection file at the end of the URL. Check Relative to Site Collection as the Connection link type and then click OK. Ex: http://intranet.contoso.com/Data Connections/creditservice.udcx

It will take a few moments to convert and save the data connection file to the library.

Page 37: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

k. Confirm that the data connection was converted successfully by examining the Details section of the Data Connections dialog box while the name of the converted data connection is selected.

l. Click Close to close the Data Connections dialog box .

m. Browse to the SharePoint data connection library.

n. Click the drop-down next to the name of the data connection – creditservice.udcx, click Approve/Reject.

o. Select the Approved option, and then click OK.

6. With the Data Connection to Azure now available, following 4 actions are needed to insert the customer information into the list.

a. Set the SSN# for the service call.

b. Call the WCF service.

c. Receive the Credit Score for the SSN#.

d. Save the data and close the form.

7. In the InfoPath form, select the Submit button.

8. From the Ribbon menu, choose Home tab.

9. Select Manage Rules.

10. Set the SSN# for Service call

a. Click New and select Action.

b. Name this rule Set SSN Value.

c. Under Run these Actions, click Add, and select Set a field’s value.

d. Click on the Browse( ) button next to the Field Textbox

e. In the dialog titled Select Field or Group, click Show advanced view.

f. From the dropdown select GetCreditScore (Secondary).

g. Under myFields, expand queryFields.

h. Expand tns:GetCreditScore.

i. Select SSNumber.

Page 38: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Figure 2Setting the SSN#

j. Click OK.

k. Back in the Rule Details dialog box, click the fx button ( ) next to the Value textbox.

l. Click Insert Field or Group.

m. In the dialog titled Select Field or Group, click Show advanced view.

n. From the dropdown select Main.

o. Under myFields, expand dataFields.

p. Expand my:SharePointListItem_RW.

q. Select SSN from the list.

Page 39: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Figure 3Inserting SSN

r. Click OK.

s. Click OK in the Insert Formula dialog box.

t. Click OK in the Rule Details dialog box.

11. Call the Azure service

a. In the Rules for the Submit button (which should still remain opened in the task pane), click New and select Action.

b. Name this rule Azure Connection.

c. Under Rule Type, select Action.

d. Under Run these actions click Add. Set the action to Query for data.

e. In the Rule Details dialog box, under Data connection, Select the GetCreditScore data connection that you created earlier of this task.

f. Click OK.

12. Receiving the Credit score for the SSN#

a. From the Ribbon menu, Choose Data and select Show Fields.

b. At the bottom of the Field window, click Show advanced view.

c. Choose Main from field groups, and expand dataFields.

d. Expand my:SharePointListItem_RW.

Page 40: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Figure 4Fields dialog

e. Right click on Credit Score and select Properties

f. Click the button ( ).

g. Select Insert Field or Group.

h. Select GetCreditScore (Secondary) from the dropdown.

i. Under myFields, expand dataFields.

j. Expand tns:GetCreditScoreResponse.

k. Select GetCreditScoreResult.

Page 41: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

Figure 5Select a Field or Group dialog

l. Click OK.

m. Click OK in the Field or Group Properties dialog box.

n. Click OK.

13. Select the Submit Button.

14. Back in the Rules for the Submit Button, Click New and select Action.

15. Name the rule Submit to SharePoint.

16. Under Rule Type, select Action.

17. Under Run these actions click Add. Set the action to Submit data.

18. In the rule details dialog box, under Data Connections, select Main Data Connection.

19. Click OK.

20. Select the Submit Button.

21. Back in the Rules for the Submit Button, Click New and select Action.

22. Name the rule Close Form.

23. Under Rule Type, select Action.

24. Under Run these actions click Add. Set the action to Close the Form.

25. Click OK.

26. From the Ribbon Menu, choose the File Tab. Select Quick Publish to publish the form. Click OK.

27. Navigate to the Customers List.

Page 42: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

28. Click Add a new Item.

29. The customized InfoPath form will be displayed. Fill in the details.

30. Click the Submit button.

The SSN# is passed to the hosted service on Azure and the Credit Score is retrieved. This credit score along with the user entered data is now inserted into the list.

Figure 6Customers- New Item dialog

31. Refresh the Customers list and check the value of Credit Score column. You will see the credit score retrieved from the Azure service is inserted into list item.

32. You will also see that the Loan Request Workflow has started automatically and a task is assigned to the approver.

Summary

InfoPath 2010 offers a codeless way to build complex and advanced forms. With Microsoft InfoPath 2010, you can customize the forms used for creating and editing items in a SharePoint list. Apart from

Page 43: Consuming Windows Communication Foundation Services …az12722.vo.msecnd.net/.../labs/azurewcfsp1-0/Lab.docx  · Web viewConsuming Windows Communication Foundation Services From

just customizing the list screens for layouts, InfoPath allows integration with other line-of-business applications.

In this lab, you created and hosted a Azure solution and learned to consumed it in the data entry screen of a SharePoint custom list.