Consuming Web Services with SharePoint

Merry Christmas! Hope you and yours are having a happy holidays.

I've been working a lot with consuming web services and DataView Web Parts (DVWP) with SharePoint lately. FrontPage 2003 lets you create these very cool things called DataView Web Parts. Basically they consume a web service (either one your write or something someone can provide) and expose the results as a webpart that you can use/re-use on your SharePoint site. With the magic of XSLT you can get the results looking grand.

This example walks you through consuming a web service from the Microsoft Money site and get live stock quotes (well, 20 minute delay anyways) all without a stitch of code. Okay, no C# written here but some people will say that coding XSLT is pretty much the same as writing code. You be the judge however the example here was to get a single stock quote web part consuming an external web service, all without having to break out your Visual Studio.NET toolkit.

First we'll need a page to add the DVWP to. This can be your default.aspx page but I prefer to create a new webpart page, stick it into a document library and edit the page from there. That way I'm not un-ghosting my default.aspx page and I can delete the doclib later and not use it in production. Either way, your choice.

  1. Load the page up into FP2003
  2. Select (or create) a Web Part Zone
  3. Select Data | Insert Data View from the menubar
  4. Expand the XML Web Services Data Source from the Task Pane
  5. Select Add to Catalog...
  6. Enter http://office.microsoft.com/Research/Providers/MoneyCentral.asmx?WSDL the Service description location. This is the URL to the Microsoft Money Web Service.
  7. Select Connect Now. This will populate the rest of the dialog with the available services
  8. Select MoneyCentralRemoteSoap from the dropdown list
  9. Select DDSQuery from the Operation list
  10. Double click on symbol in the Parameters list
  11. Enter your stock symbol in the Value field (for this post I used Canadian Pacific Railway which is "CA:CP" but you can use any valid symbol like MSFT for Microsoft, YHOO for Yahoo, etc.)
  12. Select the checkbox so you can enter this value at runtime.
  13. Double click on language in the Parameters list
  14. Enter en-US as a value here (English/United States, you can enter other values here for other languages)
  15. Click OK

This will add a new Data Source into your catalog called MoneyCentralRemote on office.microsoft.com. You can now drag and drop this data source onto a Web Part Zone. Once you do this your web part will look like this:

DDSQueryResult <StockData xmlns:dt="urn:schemas-microsoft-com:datatypes"><Quotes><Quote Symbol="CA:CP"><Last dt:dt="float">40.98</Last><LastTime dt:dt="string">10:05 AM</LastTime><LastSize dt:dt="float">100.00</LastSize><Ask dt:dt="float">40.98</Ask><Bid dt:dt="float">40.90</Bid><Open dt:dt="float">41.00</Open><Close dt:dt="float">40.80</Close><High dt:dt="float">41.00</High><Low dt:dt="float">40.61</Low><Volume dt:dt="float">20,172</Volume><Change dt:dt="float">0.18</Change><PercentChange dt:dt="float">0.44</PercentChange><EPS dt:dt="float">2.87</EPS><PE dt:dt="float">14.28</PE><SharesOut dt:dt="float">100.00</SharesOut><Currency dt:dt="string">CAD</Currency><Exchange dt:dt="string">Toronto</Exchange><Type dt:dt="string">Equity</Type><CompanyName dt:dt="string"><![CDATA[CANADIAN PACIFIC]]></CompanyName></Quote></Quotes><Attributions><Timing><![CDATA[Quotes delayed at least 20 min]]></Timing><Attribution priority="1"><![CDATA[<a href="http://www.comstock-interactivedata.com"><img border="0" align="absmiddle" src="http://office.microsoft.com/Research/Images/splgo.gif" /></a> Quotes supplied by <a href="http://www.comstock-interactivedata.com">Standard & Poor's ComStock, Inc.</a>]]></Attribution><Attribution priority="1"><![CDATA[<a href="http://moneycentral.msn.com/investor/partsub/funds/mstar.asp"><img border="0" align="absmiddle" src="http://office.microsoft.com/Research/Images/mornlgo.gif" /></a> Fund data provided by <a href="http://moneycentral.msn.com/investor/partsub/funds/mstar.asp">Morningstar, Inc.</a>]]></Attribution><Attribution priority="2"><![CDATA[<a href="http://privacy.msn.com/tou">Terms of Use</a>]]></Attribution></Attributions><Warning>NoWarning</Warning></StockData>

Now you'll want to let your users enter a stock symbol and the web part will do the lookup based on that value. Do this from inside FP2003 (I find you can't always perform a connection between a DVWP and another web part in the browser)

  1. Click on a zone and select Insert Web Part
  2. From the Task Pane select the Form Web Part and add it to the page
  3. Right click the Form Web Part in FP2003 and select Web Part Connections... from the popup menu
  4. Select Provide Form Values To in the action dropdown and click Next
  5. Select Connect to a Web Part on this page and click Next
  6. Choose the DVWP in the Target Web Part dropdown
  7. Choose Modify View Using Parameters From in the Target Action dropdown
  8. Select the column next to symbol (should be the second one) and select T1 as the dropdown value. T1 is the default name for the input field on the Form Web Part.
  9. Click Next then Finish to complete the connection

You now have a connection from the Form Web Part to your DVWP. When a user enters a stock symbol in the Form Web Part and clicks on Go, the information is fed to the DVWP (mapping the value in T1 from the Form Web Part to the symbol parameter in the DVWP). This will re-invoke the webservice behind the DVWP with the symbol value updated and return the result.

That's it! Live stock quotes from the Internet on your WSS/SPS site (this works with both) all without a single line of code. My XSLT knowledge is abysmal (read:none) so you'll have to bear with me on the formatting of the results here but I'm some of you are crafty enough to work with this. You'll probably want to format the XSLT so it displays something like this maybe:

Symbol MSFT
Last 27.01
Change +0.04
% Change +0.15%
Volume 65.82 Mil
Day's High 27.15
Day's Low 26.83

Or whatever works for you. Just do a match on the XML so you find the Last, Change, Volume, etc. nodes and make it pretty. (and if someone wants to email me a xsd file I'll update this post and probably learn about XSLT a little). In my effort to try to achieve this look from the XML returned from the web service, it keeps coming out the same. One big XML dump. Sigh.

Hope that gets you started using Web Services with FP2003 and SharePoint. I'm sure you'll have other uses that make sense to you as this is just an example.

4 Comments

  • Anyone know what happened with the moneycentral.asmx page today? Web Service seems to be down.

  • The Microsoft MoneyCentral web service is STILL down. Anyone have a work around???

  • I want to call my own application webservice directly from Sharepoint by customizing it or by some other means without any intermediate application like FrontPage 2003.
    Is it possible and if so, could you please share me the materials or web links a as soon as possible.

  • Cool stuff. Ok, Microsoft Money no longer exists. But cool how you could get that working within SharePoint.

Comments have been disabled for this content.