Plug In .NET My Services
Add Power to Your ASP.NET Applications
October 30, 2009
asp:coverstory
Languages: VB| C#
Technologies: WebServices | XML | .NET My Services
Plug In.NET My Services
AddPower to Your ASP.NET Applications
By Markus Egger
With .NET My Services, Microsoft will introduce its firstserious stab at commercial XML Web Services. The groundwork has been laid, andthe beta SDKs have been published. Microsoft is still working on the deploymentstrategy and has yet to determine who will host the data and service fabric.The core of the infrastructure will remain the same, though, so now's a goodtime to see how you'll be able to use this important technology.
The basic idea of .NET My Services (NMS) is fairlystraightforward: Allow users to take widely used features, such as calendarsand address books, online and keep the information in a centralized repository,where it is available to all kinds of applications and devices. For example,most users keep their contact lists in a local database (such as MicrosoftOutlook) or in a semi-central database, such as Exchange Server. Although theExchange Server approach is more flexible than that of the local database, it'sstill an unsatisfactory approach; it's hard to find third-party providers forless-popular server products. On top of that, solutions are often expensive becausethey are proprietary and do not use easy-to-implement APIs, such as a simplestream of XML accessed across HTTP, as would be the case with XML Web Services.
The .NET My Services Approach
NMS takes an entirely different approach. All information(as well as the business and application logic that goes with it) is hosted ona server. This is generally known as the NMS service fabric. Applications anddevices that would like to access that information do so using standardizedSimple Object Access Protocol (SOAP) requests. This allows all XML WebService-enabled devices access to the desired information (assuming appropriateauthentication), which makes it easy to use contact lists and other informationeverywhere. Note that connectivity is not required at all times becauseapplications can store information off-line, similar to the way Outlook cachesExchange information off-line today.
This is nifty, but not revolutionary ... so far. Of course,it gets better. Imagine you subscribe to a magazine, such as asp.netPRO.The magazine's Web site offers subscription services, so you simply cannavigate to the magazine's URL and enter your information manually. So far, sogood. But what if you move? Well, you would contact Informant Communications(the publisher of asp.netPRO) and request an address change. Thatdoesn't sound so bad, until you realize that you also have to do this with theother 20 magazines to which you subscribe. Then, there's the MSDN subscriptionyou need to update, and you need to tell your cell phone provider and your ISPyou've moved, too.
Of course, I wouldn't be going into all this if NMSweren't able to help in this scenario. One of the many services provided - andkeep in mind that there are a large number of services beyond the contacts andcalendar services described in this article - is named .NET My Profile. Thisservice allows you to store information about yourself in the repository, suchas your name, addresses, phone numbers, and e-mail addresses. Of course, youdon't keep this information for your own benefit (unless you are particularlyforgetful). You keep this information to let other people and organizations"subscribe" to it. This way, asp.netPRO can add your profile to themagazine's address book. Of course, this can only happen if you grant access toyour profile. This is known as giving consent. Consent is given on a rathergranular level. Perhaps you want this magazine to have access to your businessaddress, but not your home address or phone numbers. Your friend, on the otherhand, could have access to your business andmobile phone numbers.
The beauty of this system is that whenever people readyour information from their list of contacts, they get the most up-to-dateinformation (again, only the part you have consented to release to them). So,your magazine arrives at your new house automatically. In fact, it arrives atthe right address even if you live in different places throughout the year.Your old high-school buddies are able to get a hold of you, as well, becausethey always have the most up-to-date phone number. In fact, a phone numberisn't even necessary. The .NET My Services-enabled phone simply can connect to"Bob" no matter what the appropriate number is.
Start Coding
So how do you start preparing your Web site or applicationfor this technology today? The services are not yet available, but a beta SDKis. For the most up-to-date information on the SDK, visit http://www.microsoft.com/MyServices.The SDK installs locally on your development machine or server. To install it,you need SQL Server 2000, which is used to store the information. In addition,all the XML Web Service functionality is installed locally, which requiresInternet Information Server to be installed. This configuration is known as"NMS in a box." Everything runs locally, which means you don't have to connectto a test Web site that provides the service.
NMS is a bit more sophisticated than your basic XML WebService. Calls to the service fabric can include complex queries as well as aplethora of information. To accommodate that sophistication, Microsoftintroduces the XML Messaging Interface (XMI). The XMI definition is acombination of data being sent back and forth, such as contact information,calendar items, or entire documents and more; and an XML-based language namedHailStorm Data-manipulation Language (HSDL), which sends instructions to theserver. (HailStorm was the former code name of .NET My Services.) All of thatinformation is combined in a single XML document (separated by namespaces) thatis embedded into a SOAP message.
Many NMS acronyms start with the letters HS. It appears tobe safe to assume that HS stands for HailStorm. Therefore, don't be surprisedif these acronyms change.
Part of the SOAP message has to be security information.Unless proper authentication is provided, NMS will not grant access to anyinformation. In a production environment, .NET Passport provides securityinformation in the form of Kerberos security tickets. To avoid having to messwith .NET Passport in the development environment, the SDK allows you to useKerberos tickets generated by the local domain or computer. This enables thedeveloper to authenticate using local user accounts, assuming the local systemis provisioned appropriately (see the sidebar "Provisioning theService"). FIGURE 1 provides an overview of the NMSarchitecture.
FIGURE 1: .NET My Services is based onstandard SOAP requests made to the service fabric. .NET Passport providessecurity tickets that must be embedded into all requests.
A First Request to .NET My Services
You can post a simple request to NMS by composing an HSDLmessage manually. This code represents a simple query request against the MyContacts service:
xmlns:hs="http://schemas.microsoft.com/hs/2001/10/core"
xmlns:m="http://schemas.microsoft.com/hs/2001/10/
myContacts">
The queryRequest tag defines the overall nature ofthe message. The namespace definitions are required because HSDL will beintermingled with the actual data once it is returned (and, for differentmessage types, HSDL will be sent along with the request). Most NMS examples youwill see use the hs namespace for HSDL commands and the mnamespace for the returned data. Note that the hs namespace remains thesame for all HSDL requests, and the m namespace is linked to thenamespace definition for each individual service, such as My Contacts.
The actual query is defined in the xpQuery tag. Theletters xp stand for XPath, which should give you an idea of the options youhave in the select attribute. For the developer, an entire NMSrepository appears as one huge XML document that can be queried using XPathpatterns. In the example in the previous code snippet, the query requestagainst the My Contacts service, all myContacts elements stored in theuser's repository are returned. The result set will contain a stream similar tothe one shown in FIGURE 2. (You'll learn about how to post the query to theservice in a bit.) This represents a typical set of tags used by the MyContacts service. Note that many more tags are available but are optional. Fora full specification of the My Contacts schema, consult the SDK documentation.
xmlns:hs="http://schemas.microsoft.com/hs/2001/10/core"
xmlns:m="http://schemas.microsoft.com/hs/2001/10/
myContacts"
xmlns:mp="http://schemas.microsoft.com/hs/2001/10/
myProfile">
id="B51F6919-E78F-445B-984C-8BBAD4E28C32">
Bill
Gates
BillG
id="855AF6CE-9060-4D45-A7D7-97BB1DE4981D">
id="97CEEAF3-51BC-41FD-A2A5-F4DE73233D17">