OWASP O2 Platform Blog

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.

 Here is a Weather WebService:

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");

//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);


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

April 3, 2011 - Posted by | .NET, WS


  1. […] 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 […]

    Pingback by O2 Script: consume webservices by using the WSDL’s C# « O2Platform.com for Developers | April 3, 2011 | Reply

  2. […] O2 Script: Using Reflection to Invoke Bing Search Web Service […]

    Pingback by Script to fetch and present large number of Wordpress.com blog entries « O2Platform.com for Developers | April 16, 2011 | Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: