[Mono-list] Writing a (ASP.NET) Web Service Client using Mono-0.29 on Libranet2.8

Gonzalo Paniagua Javier gonzalo@ximian.com
Wed, 14 Jan 2004 15:41:13 +0100


El mar, 13-01-2004 a las 22:15, Martin Gamsjaeger escribió:
> Hi, 
>  
> I just installed Mono-0.29 from sources on my Libranet2.8 desktop. Everything ran very 
> smooth, and after reading a few hints on how to complete the install (getting the 
> missing asp_state.exe.config and commenting out the bytefx.snk usage) I had an almost 
> ready working version of Mono! Let me say here: Thanks! it's great :-) 
>  
> Still, I'm facing two little problems. The first one Mono (XSP) not being able to run the 
> ConverterService.asmx with the following error: 
>  
> --------------------------- 
> Compilation Error 
>  
> Description: Error compiling a resource required to service this request. Review your 
> source file and modify it to fix this error.  
>  
> Error message: /tmp/tmp6544406f.cs(58,0) : error CS0246: Could not find attribute 
> 'TraceExtension' (are you missing a using directive or an assembly reference ?) 
[...]
>   
> File name: /home/ofi/gamsl/mono/xsp-0.8/server/test/ConverterService.asmx 

You're running it from the source code directory. You should run 'make
install', which will compile some source files and install them as dlls
in the bin directory.

>  
> Source File: /tmp/tmp6544406f.cs 
> ---------------------------------------------------- 
>  
> Before I changed web.config the situation was even worse because mono wasn't able to 
> run any of it's web service examples, because the web.config file coming with release 
> 0.29 seems somehow broken. I could improve this situation by changing web.config to 
> the following (changes in the <soapExtensionTypes> section): 

Same here. Run 'make install' and then run xsp in the directory where
the samples are installed ($prefix/share/doc/xsp/test).
[...]
 
> 
> My second and actually more important question is how to write a client for a web 
> service. I know that with microsofts .net implementation one has to use the wsdl.exe tool 
> to generate a c# proxy file, in which you specify the namespace for the proxy, but there 
> seems to be no equivalent way in mono, since the proxy file is automatically generated. I 
> now have the problem that my client will not find my web service and complain with the 
> following error message: 
>  
> --------------------------------------- 
> Description: Error compiling a resource required to service this request. Review your 
> source file and modify it to fix this error.  
>  
> Error message: /home/ofi/gamsl/mono/xsp-0.8/server/test/Adder.aspx.cs(13,0) : error 
> CS0246: Cannot find type `TimeService' 
> (0,0) : error failed: 1 error(s), 0 warnings 
>   
> File name: /home/ofi/gamsl/mono/xsp-0.8/server/test/Adder.aspx.cs 

Again.

> -------------------------------------------------------------------------------------------------------- 
>  
> Here is my sample service and client: 
>  
> TimeService.asmx: 
> ----------------------------- 
>  
> <%@ WebService Language="C#" Class="TimeService"%> 
>  
> using System; 
> using System.Text; 
> using System.Web.Services; 
>  
> public class TimeService : WebService 
> { 
>   [WebMethod(Description="Returns the current time")] 
>   public string GetTime() 
>   { 
>     return System.DateTime.Now.ToLongTimeString(); 
>   } 
> } 
>  
> TimeClient.aspx: 
> -------------------------- 
>  
> <%@ Page Language="C#" Inherits="TimeClientPage" Src="TimeClient.aspx.cs"%> 
> <html> 
>   <head><title>Time on server</title></head> 
>   <body> 
>     <form method="post" Runat="server"> 
>       <b>Click for time on Server</b> 
>       <asp:Button ID="ok" Text="Time" OnClick="ButtonClick" Runat="server"/> <br> 
>       <asp:Label ID="time" Text="Here comes the time ..." Runat="server"/> 
>     </form> 
>   </body> 
> </html> 
>  
> TimeClient.aspx.cs: 
> ------------------------------ 
>  
> using System; 
> using System.Web.UI; 
> using System.Web.UI.WebControls; 
>  
> public class TimeClientPage : Page 

It's recommended (if not mandatory...) to put your class inside a
namespace.

> { 
>   protected Label time; 
>   protected Button ok; 
>  
>   public void ButtonClick(object sender, EventArgs e) 
>   { 
>     TimeService service = new TimeService(); 
>     total.Text = service.GetTime(); 
>   } 
> } 
>  
> All the files reside in "xsp-0.8/server/test" and xsp.exe is started from this folder. 
>  
> Now my question: How can I specify the namespace where to find the service? If i put 
> the service itself in a namespace (that is in file TimeService.asmx writing "namespace 
> XXX { ... }) it won't work. Strange is also that when I ask the TimeService Object about 
> it's namespace using "string ns = new TimeService().GetType().Namespace" it gives me 
> "http://tempuri.org/" which is no valid namespace name in C# (at least it gives me syntax 
> errors when I try "using http://tempuri.org/") 

Just put 'Inherits="Namespace.ClassName"'.

>  
> Can anyone tell me what I'm doing wrong here? 

It's all about installing things properly. So, to summarize:
      * Run make install and run xsp from the directory where it
        installs the tests.
      * For your TimeClient.aspx.cs, compile it into a dll and that dll
        deployed in bin directory.ç

-Gonzalo