O2 Script: consume webservices by using the WSDL’s C#
(as a follow from O2 Script: Using Reflection to Invoke Bing Search Web Service) Here is how one can consume webservices by using a (previously created) C# of the WSDL:
var _GlobalWeather = new GlobalWeather();
_GlobalWeather.GetWeather("Porto", "Portugal");
return _GlobalWeather;
//O2File:C:\O2\_tempDir\4-3-2011\wsdl_tmpC7EC\GlobalWeather.cs
//O2Ref:System.Web.Services.dll
//Note: the GlobalWeather.cs file was created with the command:
//
// return new DotNet_SDK_WSDL().wsdl_CreateCSharp("http://www.webservicex.net/globalweather.asmx?WSDL");
// //O2File:DotNet_SDK_WSDL.cs
// //using O2.XRules.Database.Languages_and_Frameworks.DotNet
Here is Bing API version, note how (when compared with this version (O2 Script: Using Reflection to Invoke Bing Search Web Service) which is reflection based) all variable references are strongly typed)
var AppID = @"C:\O2\_USERDATA\accounts.xml".credential("Bing_API").password();</pre>
var _BingService = new BingService();
var _parameters = new SearchRequest();
_parameters.AppId = AppID;
_parameters.Sources = new SourceType[] { SourceType.Web };
_parameters.Query = "OWASP";
var response = _BingService.Search(_parameters );
return response.Web.Results;
//O2File:C:\O2\_tempDir\4-3-2011\wsdl_tmp107F\BingService.cs
//O2Ref:System.Web.Services.dll
//O2File:SecretData_ExtensionMethods.cs
O2 Script: Using Reflection to Invoke Bing Search Web Service
These script makes extensive use of O2′s reflection APIs to dynamically consume and invoke an WSDL.
var wsdlToLoad = @"http://www.webservicex.net/globalweather.asmx?WSDL";
var wsdlAssembly = new DotNet_SDK_WSDL().wsdl_CreateAssembly(wsdlToLoad);
var wsdlMethods = wsdlAssembly.webService_SoapMethods();
var getCitiesByCountry = assembly.type("GlobalWeather").method("GetCitiesByCountry") ;
//.method("GetCitiesByCountry"); var globalWeather = assembly.type("GlobalWeather").ctor();
return globalWeather.invoke("GetCitiesByCountry", "Portugal");
//return globalWeather.invoke("GetWeather", "Lisboa", "Portugal");
//O2File:DotNet_SDK_WSDL.cs
//using O2.XRules.Database.Languages_and_Frameworks.DotNet
Here is Bing’s search API:
var wsdlToLoad = "http://api.search.live.net/search.wsdl";
var assembly = new DotNet_SDK_WSDL().wsdl_CreateAssembly(wsdlToLoad); //cache the created assembly to make it faster
//var assembly = @"C:\Users\o2\AppData\Local\Temp\f3kx9cxv.dll".assembly();
var searchBingFor = "OWASP";
var currentType = "BingService";
var currentMethod = "Search";
var AppID = @"C:\O2\_USERDATA\accounts.xml".credential("Bing_API").password();
var searchRequest = assembly.type("SearchRequest").ctor();
searchRequest.property("Query", searchBingFor);
searchRequest.property("AppId", AppID);
var sourceType = assembly.type("SourceType");
var webEnum = sourceType.enumValue("Web");
var sources = sourceType.createArray(webEnum);
var methodParameters = assembly.type(currentType).method(currentMethod).create_LiveObject_From_MethodInfo_Parameters();
searchRequest.property("Sources", sources);
methodParameters.property("parameters",searchRequest);
var response = assembly.type(currentType).ctor()
.invoke(currentMethod, methodParameters.getProperties_AsArray());
return response.property("Web").property("Results") ;
//using System.Reflection
//using O2.XRules.Database.Languages_and_Frameworks.DotNet
//O2File:DynamicTypes.cs
//O2File:DotNet_SDK_WSDL.cs
//O2File:SecretData_ExtensionMethods.cs

