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.
- Load the page up into FP2003
- Select (or create) a Web Part Zone
- Select Data | Insert Data View from the menubar
- Expand the XML Web Services Data Source from the Task Pane
- Select Add to Catalog...
- Enter http://office.microsoft.com/Research/Providers/MoneyCentral.asmx?WSDL the Service description location. This is the URL to the Microsoft Money Web Service.
- Select Connect Now. This will populate the rest of the dialog with the available services
- Select MoneyCentralRemoteSoap from the dropdown list
- Select DDSQuery from the Operation list
- Double click on symbol in the Parameters list
- 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.)
- Select the checkbox so you can enter this value at runtime.
- Double click on language in the Parameters list
- Enter en-US as a value here (English/United States, you can enter other values here for other languages)
- 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:
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)
- Click on a zone and select Insert Web Part
- From the Task Pane select the Form Web Part and add it to the page
- Right click the Form Web Part in FP2003 and select Web Part Connections... from the popup menu
- Select Provide Form Values To in the action dropdown and click Next
- Select Connect to a Web Part on this page and click Next
- Choose the DVWP in the Target Web Part dropdown
- Choose Modify View Using Parameters From in the Target Action dropdown
- 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.
- 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:
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.