Microsoft.SharePoint.WebControls.SoapDataSource - An easy way to create web service data source in SharePoint

by James 6/2/2008 2:22:00 PM

SoapDataSource from Microsoft.SharePoint assembly is a concreted class of BaseXmlDataSource and also implemented with IDataSource interface.

It can be used for making web service call and served as data source to your SharePoint custom controls / web parts.

For example, We have created a web service which returns stock quote and it has been depolyed as SharePoint web serivce in ~SiteUrl/_layouts/.

This web service has following properties

- Web service name : EnhancedSharePriceWebService.asmx

- Web service namespace URI: http://jamestsai.net

- Web serivce action name : GetMultiQuotes

- Input parameter: symbols (stock symobls in comma-saparator format. e.g. MSFT;AAPL;GOOG)

SOAP 1.1 request

soap1-1

SOAP 1.1 response

SoapResponse

SoapDataSource contains some properties that you must set values to it. They are:

SoapDataSource.SelectServiceName - Web service name

SoapDataSource.SelectUrl - Web service full URL

SoapDataSource.WsdlPath - Web service WSDL path

SoapDataSource.SelectPort - Web service SOAP portocal

SoapDataSource.SelectAction - Web service action name

SoapDataSource.SelectCommand - SOAP request command

SoapDataSource.SelectParameters - Parameters

 

Following code sample shows how to set up SoapDataSource with parameter to retrive data from our share price quote web service.

private SoapDataSource CreateDataSource(SPSite site)
{
     string serverUrl = site.Url; //Get SharePoint root site URL
     SoapDataSource datasource = new SoapDataSource(); //Initiate new SoapDataSource obj
     string symbols = "MSFT;AAPL;GOOG";
     datasource.SelectServiceName = "EnhancedSharePriceWebService";
     datasource.SelectUrl = serverUrl + "/_layouts/EnhancedSharePriceWebService.asmx";
     datasource.WsdlPath = serverUrl + "/_layouts/EnhancedSharePriceWebService.asmx?WSDL";
     datasource.SelectAction = http://jamestsai.net/GetMultiQuotes; //SOAP Action name
     datasource.SelectPort = "EnhancedSharePriceWebServiceSoap"; //SOAP Protocal name
     datasource.SelectParameters.Add("symbols", symbols);
     datasource.SelectCommand = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> <soap:Body><GetMultiQuotes xmlns=\"http://jamestsai.net/\"> <symbols>{symbols}</symbols></GetMultiQuotes></soap:Body></soap:Envelope>";

}


//Create SoapDataSource by calling CreateDataSource method above
SoapDataSource bindedDS = CreateDataSource(SPContext.Current.Site);
//Get return data as XmlDocument
XmlDocument xdoc = bindedDS.GetXmlDocument();

If you have setup everything correctly, You should be able to see the web serivce result in XmlDocument xdoc. You can also bind SoapDataSource to your data-bound controls.

 

James

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

Programming | SharePoint

Comments

Add comment


 

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen Adopted by James Tsai

About the author

Name of author James Tsai
.NET and SharePoint consultant

E-mail me Send mail

Calendar

<<  January 2009  >>
MoTuWeThFrSaSu
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678
View posts in large calendar

Certifications

MCPD
MCTS

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009

Sign in