OWASP O2 Platform Blog

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;


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


April 3, 2011 Posted by | .NET, WS | 1 Comment

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 | 2 Comments

Using a webservice to get the IP Address

These scripts show how to use this xml feed to access information about the ‘current user IP address’.

This first code snippet shows how to get the IP address value from the downloaded xml file:

var currentIpAddress = @"<a href="http://ip-address.domaintools.com/myip.xml">http://ip-address.domaintools.com/myip.xml</a>"
return currentIpAddress; 


This second example will show a more advanced script which downloads the XML feed  and displays it in table list (the “IP Address history” was added for the cases where one wants to confirm a IPAddress change (for example in the case of connecting to a VPN)):

//var topPanel = panel.clear().add_Panel();
var topPanel = O2Gui.open<Panel>("IPAddress", 650,400);
var tableList = topPanel.add_TableList("IP Details (select to copy value to clipboard)");
      if(selectedRows.notNull() &&  selectedRows.size()==1)      

var ipAddress = tableList.insert_Above<Panel>(40)
         .add_Label("Your current IP is:").size(20)
var history = tableList.insert_Right<Panel>(250).add_GroupBox("IPAddress History").add_TextArea();
Func<Dictionary<string,string>> getIpData =
   var ipServiceUrl = @"<a href="http://ip-address.domaintools.com/myip.xml">http://ip-address.domaintools.com/myip.xml</a>";
   var xmlData = ipServiceUrl.uri().getHtml();   
   if (xmlData.valid())
    var ipData = new Dictionary<string,string>();
    foreach(var element in xmlData.xRoot().elements())
     ipData.Add(element.name(), element.value());    
    return ipData;    
   return null;

Action showIpData =
   ipAddress.set_Text("fetching data...").textColor(Color.DarkGreen); 
   var ipData = getIpData(); 
    history.append_Line("[{0}]: {1}".format(DateTime.Now.str(),ipData["ip_address"]));

ipAddress.append_Link("refresh", ()=>showIpData()).left(450).top(12);

return "ok";

Note: this script is included in the Dynamic Scripts included with O2: Util – View Current IP Address info.h2

November 26, 2010 Posted by | WS | Leave a comment