[Mono-list] Writing a (ASP.NET) Web Service Client using Mono-0.29 on Libranet2.8
Martin Gamsjaeger
gamsl@abschneiden.com
Tue, 13 Jan 2004 22:15:47 +0100
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 ?)
/tmp/tmp6544406f.cs(67,0) : error CS0246: Could not find attribute 'TraceExtension'
(are you missing a using directive or an assembly reference ?)
/tmp/tmp6544406f.cs(77,0) : error CS0246: Could not find attribute 'TraceExtension'
(are you missing a using directive or an assembly reference ?)
/tmp/tmp6544406f.cs(94,0) : error CS0246: Could not find attribute 'TraceExtension'
(are you missing a using directive or an assembly reference ?)
/tmp/tmp6544406f.cs(111,0) : error CS0246: Could not find attribute 'TraceExtension'
(are you missing a using directive or an assembly reference ?)
/tmp/tmp6544406f.cs(30,0) : error CS0246: Could not find attribute 'Dump' (are you
missing a using directive or an assembly reference ?)
/tmp/tmp6544406f.cs(31,0) : error CS0246: Could not find attribute 'Encrypt' (are you
missing a using directive or an assembly reference ?)
(0,0) : error failed: 7 error(s), 0 warnings
File name: /home/ofi/gamsl/mono/xsp-0.8/server/test/ConverterService.asmx
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):
--------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="mono.aspnet">
<section name="acceptEncoding"
type="Mono.Http.AcceptEncodingSectionHandler, Mono.Http"/>
</sectionGroup>
</configSections>
<system.web>
<customErrors mode="Off"/>
<webServices>
<soapExtensionTypes>
<add type="DumpExtension, extensions" priority="0" group="0" />
<add type="EncryptExtension, extensions" priority="0" group="0" />
<add type="TraceExtension, extensions" priority="0" groups="0" />
</soapExtensionTypes>
</webServices>
<authentication mode= "Forms">
</authentication>
<httpModules>
<add name="AcceptEncodingModule" type="Mono.Http.AcceptEncodingModule,
Mono.Http"/>
</httpModules>
</system.web>
<mono.aspnet>
<acceptEncoding>
<!-- Change disabled to 'no' to enable gzip content encoding -->
<add encoding="gzip" type="Mono.Http.GZipWriteFilter, Mono.Http"
disabled="no" />
</acceptEncoding>
</mono.aspnet>
<appSettings>
<add key="MonoServerDefaultIndexFiles"
value="index.aspx, Default.aspx, default.aspx, index.html, index.htm" />
<add key="DBProviderAssembly"
value="Mono.Data.PostgreSqlClient"/>
<add key="DBConnectionType"
value="Mono.Data.PostgreSqlClient.PgSqlConnection"/>
<add key="DBConnectionString"
value="hostaddr=127.0.0.1;user=monotest;password=monotest;dbname=monotest"/>
</appSettings>
</configuration>
-------------------------
After doing this I was able to run TestService.asmx and a little example service I wrote
my own, but I still am not able to run ConverterService.asmx with the above error
message. What needs to be done here?
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
--------------------------------------------------------------------------------------------------------
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
{
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/")
Can anyone tell me what I'm doing wrong here?
Thanks in advance for your help and your great piece of software!
gamsl