I have a little problem with a webservice. I reproduced the problem in the
following simplified example.
I just create a new C# ASP.NET webservice and a c# console application.
I added a new class test to the namespace of the webservice which I try to
access from the console
application.
//Service1.asmx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace WebService2
{
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
InitializeComponent();
}
#region Component Designer generated code
private IContainer components = null;
private void InitializeComponent()
{
}
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
[WebMethod]
public string HelloWorld(test t)
{
return "Hello World";
}
}
public class test
{
public test(){}
public int someInt;
private int anotherInt;
public int TheInt
{
get
{
return anotherInt;
}
set
{
anotherInt=value;
}
}
public int returnInt()
{
return 4;
}
}
}
//Class1.cs
using System;
// I added Webservice2 as web reference ws1
using ConsoleApplication1.ws1;
namespace ConsoleApplication1
{
class Class1
{
static void Main(string[] args)
{
test t=new test();
int a=t.someInt;
int b=t.returnInt(); //this produces an error CS0117
Console.WriteLine("Returned value="+b.ToString());
}
}
}
2 things are bugging me:
First: it does not compile! It gives me the following error:
Class1.cs(21): error CS0117: 'ConsoleApplication1.ws1.test' does not contain
a definition for 'returnInt'
The console application does not seem to have access to the public functions
of the class test, but it does have
access to the public properties.
Is this how it is supposed to be or am I doing something wrong?
Does anyone have a solution?
Pleas don't just point me to http://support.microsoft.com/?id=821175 since I
already saw this, I
only don't see how this fits in here.
Second: why can the console application only see the class test when I use
it as a parameter
in a [webmethod]? If I remove
"test t"
from
public string HelloWorld(test t),
I get:
Class1.cs(20): The type or namespace name 'test' could not be found (are you
missing a using directive or an assembly reference?)