Tag Archives: ASP.NET

Testing a .NET .asmx Web Service from LINQPad

Great post here about using the Visual Studio Command Prompt tools to pull the WSDL from a .NET .asmx (traditional, non-WCF) web service and compile a standalone class library which encapsulates the interface.  Basically, run a Visual Studio prompt, switch to a writable directory and run these two commands:

Convert WSDL to service reference .cs classes:

wsdl http://z.com/MyService.asmx

That will create classes in the global namespace and name class file based on the service URL.

Alternately, you can add a namespace and control the name of the output file:

wsdl http://z.com/MyService.asmx /n:MyServiceNamespace /o:MyService.cs

Compile into a class library:

csc /t:library MyService.cs

Then in LINQPad add a reference to the new .dll and the System.Web.Services .NET library.

Then you can write this in LinqPAD:

// create an instance of the service 
var service = new MyService();

// Or namespace version
var service2 = new MyServiceNamespace.MyService();
// invoke a web method and dump the results


Cast an ArrayList as IEnumerable (and Even IQueryable)

Again, not really sure why this works. Based on the original from here.

ArrayList students = GetStudents();
var query =
  from student in students.Cast()
  where student.Score > 80
  select new { student.ID, student.Name };

This is what I ended up with:

IQueryable dcs = 
(IQueryable)getChildControlsByType(ContactDetailsView, "System.Web.DynamicData.DynamicControl").Cast().AsQueryable();

Where the method getChildControlsByType is returning a generic ArrayList (but always of some kind of control). I guess the “Cast,” being an extension method, returns a typed IEnumerable, which can be turned into an IQueryable. Without the Cast, this code throws an exception.