By Mats Halfvares, the Content Studio development team

Calling a regular Web service from within ASP.NET requires proxy classes that encapsulates the logic needed. In Visual Studio, these classes are created automatically when you add a new Web reference to your project. In Content Studio however, these proxy classes are currently not supplied automatically but can easily be created by using the WSDL-tool included in .NET framework. After creating the proxy class file you can either compile the class file to a .DLL library or import the content of the class file to Content Studio by creating a new code file in the System/App_Code Content Studio folder.

Creating the proxy class

The instructions below can be performed on any computer that has the .NET Framework 2.0 (or later) SDK or Visual Studio 2005 installed.
Start a new command window and navigate to the folder where you like the proxy class file to be created.

For the .NET Framework tools to function properly, you must set your Path, Include, and Lib environment variables correctly. Set these environment variables by running SDKVars.bat, which is located in the <sdk>\v2.0\Bin directory. SDKVars.bat must be executed in every command shell.

Assuming that your Web Service can be found at you can use the following command to create the proxy class:

Wsdl.exe /language:CS ""

This will create the file MyService.cs in the current directory

Now you have two options

  • Either, you can compile the class file into a .DLL library that you can upload into the System/Assemblies folder in Content Studio.
    The following command will compile the file into a library. (It is also necessary to include the System.Xml.dll and System.Web.Services.dll assemblies).

    csc /out:MyService.dll /t:library /r:System.XML.dll /r:System.Web.Services.dll MyService.cs

    Finally, upload the generated assembly (MyService.dll) into the System/Assemblies folder in Content Studio.
  • Or, you can create a new code file, named "MyService" in the System/App_Code/CSCode folder in Content Studio and paste in the content of the proxy class file.
    When you are finished, you must Approve the new code file.

Calling the web service

Provided that all went well so far, you now are ready to consume the web service directly from your Content Studio page. You call the Web Service as any ordinary .NET object. Thus, if your web service contains the method GetData you can use the following code.

  MyService ms = new MyService(); 
  string data = ms.GetData();
  Dim MyService As New MyService()
  Dim data As String = ms.GetData()