Stellt den schreibgeschützten Zugriff auf Eigenschaften und
Methoden bereit, die externe Datenquellen anbinden.
Namensraum: IFS.Taurus.DataSourceService.InterfaceAssembly: IFS.Taurus.DataSourceService.Interface (in IFS.Taurus.DataSourceService.Interface.dll) Version: 1.2.0.1 (1.2.0.1)
Syntax
C# |
---|
public interface IDataSourceService |
Beispiele
Im folgenden Quelltextbeispiel wird die Verwendung von Methoden der
IDataSourceService-Schnittstelle zum Anbinden von Web-Services
für die Ermittlung von Wetterdaten durch den WebServiceProvider
veranschaulicht.
Für die Ausführung der Web-Service-Anfrage GetCityWeatherByZIP verwendet der
WebServiceProvider die Web-Service-Vorlage GetCityWeatherByZIP.xml.
Diese enthält den Platzhalter $PARAM_ZIP$, der zur Laufzeit mit dem Wert 94129
befüllt wird.
C# | Kopieren |
---|---|
using System; using System.Collections.Generic; using IFS.Common; using IFS.Taurus.TaurusPlatform.Interface; using IFS.Taurus.DataSourceService.Interface; class Sample { static void Main(string[] args) { // Datenanbieter für Taurus® Web-Services ermitteln (WebServiceProvider) string category = "TAURUS_WEBSERVICES"; IDataSourceService tws = GetWebServices(category); if (tws == null) { // Fehlerbehandlung return; } // Wetterbericht für San Francisco via Web-Service ermitteln string zipCode = "94129"; string weatherReport = GetWeatherReportFromWebService(tws, zipCode); if (string.IsNullOrEmpty(weatherReport)) { // Fehlerbehandlung } // Wetterbericht auswerten } private static IDataSourceService GetWebServices(string category) { IDataSourceService resultService = null; // Objekt für den Zugriff auf das Taurus® DataProcurement erzeugen ITaurusPlatform tp = null; TaurusPlatformFactory.Create(out tp); if (tp == null) { // Fehlerbehandlung return null; } // Liste mit Datenanbietern für externe Datenquellen ermitteln IList<IDataSourceService> dssList; ErrorCode err = tp.GetDataSourceServiceList(out dssList); if ((err != ErrorCode.OK) || (dssList == null)) { // Fehlerbehandlung return null; } // Datenanbieter anhand der Kategorie bestimmen foreach (IDataSourceService dss in dssList) { if (dss.Category == category) { resultService = dss; break; } } // wenn kein passender Datenanbieter gefunden wurde, // Backend der angegebenen Kategorie laden if (resultService == null) { foreach (IDataSourceService dss in dssList) { try { if (dss.LoadBackend(category) == ErrorCode.OK) { resultService = dss; break; } } catch (NotImplementedException niEx) { // Fehlerbehandlung } } } return resultService; } private static string GetWeatherReportFromWebService(IDataSourceService ws, string zipCode) { string result = string.Empty; ErrorCode err = ErrorCode.Invalid; Dictionary<string, string> attributes = new Dictionary<string, string>(); attributes.Add("uri", "http://wsf.cdyne.com/WeatherWS/Weather.asmx"); // Web-Service für Wetterdienste ermitteln List<string> dsIds = null; err = ws.GetDataSources(attributes, out dsIds); if (err != ErrorCode.OK) { // Fehlerbehandlung return null; } Dictionary<string, string> filter = new Dictionary<string, string>(); // Name der Web-Service-Vorlage filter.Add("TEMPLATE", "GetCityWeatherByZIP.xml"); // Zeitüberschreitung filter.Add("REQUESTTIMEOUT", "5"); // Ersetzungsparameter für die Platzhalter der Web-Service-Vorlage filter.Add("PARAM_ZIP", zipCode); filter.Add("SOAPACTION", "http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP"); // Web-Service-Anfrage "GetCityWeatherByZIP" ausführen err = ws.Query(dsIds[0], filter, out result); if (err != ErrorCode.OK) { // Fehlerbehandlung return null; } return result; } } |
Xml | Kopieren |
---|---|
<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:weat="http://ws.cdyne.com/WeatherWS/"> <soapenv:Header/> <soapenv:Body> <weat:GetCityWeatherByZIP> <weat:ZIP>$PARAM_ZIP$</weat:ZIP> </weat:GetCityWeatherByZIP> </soapenv:Body> </soapenv:Envelope> |