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

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


SOAP 1.1 response


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.



blog comments powered by Disqus