Saturday, April 22, 2006

web services: no source code on the server. compiled to dll

Approach Two: no source code on the server

Cons: extra step, compilation

Pros: seems faster than compiled-on-the-fly, no source code on server, more secure

create a directory on server, c:\testCompiledWs

create a virtual directory named SoSharp on IIS, pointing to c:\testCompileWS

*** create webservices on your development machine. 2 step ***

Step 1 of 2.

create a file geek.cs on your development machine...

  

using System;

using System.Web.Services;

using System.Web.Services.Protocols;

public class OfTheTitans : WebService
{


[WebMethod]
public string Interest()
{
return " batman " + DateTime.Now.ToString();
}

};



...create a file geek.cs on your development machine

Step 2 of 2.

compile geek.cs to dll...

csc.exe /t:library geek.cs

Note: this will create geek.dll on your development machine

...compile geek.cs to dll

*** deploy geek.dll to your server. 2 steps ***

Step 1 of 2.

create a directory bin on server on c:\testCompiledWs

copy geek.dll on server on to c:\testCompiledWs\bin

Step 2 of 2.

create a file anorak.asmx on c:\testCompiledWs\bin ...

<%@ WebService Language="C#" CodeBehind="geek.cs" class="OfTheTitans" %>

... create a file anorak.asmx

Note: To test your webservices on your development machine, open your favorite browser, visit http://yourserveraddresshere/SoSharp/anorak.asmx

*** consume your webservices on your development machine. 3 steps ***

Step 1 of 3.

wsdl.exe http://yourserveraddresshere/SoSharp/anorak.asmx

Note: this will create OfTheTitans.cs on your development machine

Step 2 of 3.

create a file useanorak.cs on your development machine ...


public class First
{
public static void Main()
{
OfTheTitans o = new OfTheTitans();

System.Console.WriteLine("C# " + o.Interest());
}

}


...create a file useanorak.cs

Step 3 of 3.

compile and run the application...

csc.exe useanorak.cs OfTheTitans.cs

useanorak.exe

...compile and run

*** consume your webservices on your development machine, using VB.NET. 3 steps ***

Step 1.

wsdl.exe /l:vb http://yourserveraddresshere/SoSharp/anorak.asmx

Note: this will create OfTheTitans.vb on your development machine

Step 2.

create a file useanorak.vb on your development machine ...


Public Class First

Public Shared Sub Main()

Dim o As OfTheTitans = new OfTheTitans()

System.Console.WriteLine("VB " & o.Interest())

End Sub

End Class

...create a file useanorak.vb

Step 3.



compile and run the application...

vbc.exe useanorak.vb OfTheTitans.vb

useanorak.exe

...compile and run


Note:

OfTheTitans.cs can also be compiled to dll so other language can use it as well, to consume OfTheTitans.dll in useanorak.vb, use /r compile option, reference:

vbc /r:OfTheTitans.dll useanorak.vb

this will create useanorak.exe

No comments: