Today, I would like to discuss the technical direction we have taken for Monitor Analytics GeoAnalyzer which was built using Silverlight and web services in ASP.NET 3.5.
A Silverlight application communicates to an ASP.NET 3.5 web application using Web Services in order to achieve the task of talking to databases, registry, and reading / writing of files. The above would have been complex to acheive in Silverlight flawlessly as those tasks are executed in a web application. Web Services are the medium that connects Silverlight and ASP.Net 3.5 applications.
GeoAnalzyer for SharePoint is a SharePoint webpart that is built in Silverlight mashing Virtual Earth with data from a SQL Server. It was important to fully leverage Web Services in order to provide the ability to
The steps below describe in detail how web services are used in Silverlight based custom SharePoint web parts that communicate with databases:
A. Creating an ASP.NET Web Service(.asmx) in Visual Studio
- Create a web application project.
- Add Service.asmx file using feature ‘Add New Item’. (Please note the Class name here)
- Assign Strong name key to web application using properties of project.
- Build Web Application.
- Deploy the dll in Global Assembly Cache.
- Open the service.asmx file
- Replace the existing WebService directive with (Note. In Service.asmx, provide class name , namespace and public key token)
<%@ WebService Language=”C#” Class=”MAGeoAnalyzerService, MA.GeoAnalyzerWeb,Version=1.0.0.0, Culture=neutral, PublicKeyToken=Az2dca340f2dok8″ %>
- Make web application project start up file to MAGeoAnalyzerService.asmx
- Run the web application project once by pressing F5 and note the URL. Provide this URL in Disco command in following step.
B. Generating and Modifying Static Discovery and WSDL Files
- Go to Start -> All Programs ->Microsoft visual studio 2008 ->Visual Studio Tools -> Visual Studio 2008 Command Prompt
- Provide your web service URL with Disco.exe here (Example. disco.exe http://localhost:12881/Monitor GeoAnalyzerWeb/MAGeoAnalyzerService.asmx)
- WSDL & DISCO file would be generated.
- Move WSDL & DISCO files from the solution folder to your project folder (we did search for disco file, “MAGeoAnalyzerService.disco”).
- In WSDL & DISCO file
Replace
<?xml version=“1.0“ encoding=“utf-8“?>
With
<%@ Page=“” Language=“C#“ Inherits=“System.Web.UI.Page“ %>
<%@ Assembly=“” Name=“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral,PublicKeyToken=71e9bce111e9429c“ %>
<%@ Import=“” Namespace=“Microsoft.SharePoint.Utilities“ %>
<%@ Import=“” Namespace=“Microsoft.SharePoint“ %>
<% Response.ContentType = “text/xml“; %>
6 In .DISCO file replace existing contract reference and SOAP address tags
<contractRef ref=“”<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request) + “?wsdl“),Response.Output); %>
docRef=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>
xmlns=”<http://schemas.xmlsoap.org/disco/scl/>” />
<soap address=“”<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>
xmlns:q1=”<http://tempuri.org/>” binding=”q1:HelloWorld”
xmlns=”<http://schemas.xmlsoap.org/disco/soap/>” />
<soap address=“”<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>
xmlns:q2=”<http://tempuri.org/>” binding=”q2:ServiceSoap12″ xmlns=”http://schemas.xmlsoap.org/disco/soap/>” />
7 In the .wsdl file, make the following similar substitution for the SOAP address that is specified
<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> />
8 Rename both files in the respective formats servicedisco.aspx and servicewsdl.aspx so that your service is discoverable through Windows SharePoint Services.
C. Copying the Web Service Files to the _vti_bin Directories
- Copy the MAGeoAnalyzerService.asmx, MAGeoAnalyzerServicedisco.aspx, MAGeoAnalyzerServicewsdl.aspx files to c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI Now you can go to any of the existing SharePoint site in Internet information Services(inetmgr) and go to _vti_bin folder and select your .asmx file and browse it.
Thus, the web service created using the above procedure can be deployed in any of the SharePoint site on Internet Information Services(inetmgr) and can be used by any of the port of the site. This will work for Windows Server 2003, Windows Server 2008 Operating system and Windows 7.
Reference used : http://msdn.microsoft.com/en-us/library/ms464040.aspx
-Idrees