Thursday, April 06, 2006
WSRF.NET and System.Object
There is an issue on how to use System.Object as parameter or return value in web method.
The solution is extremely simple. But it takes me almost two days to figure that out. :-))
Step 1.
The you can define your web method like
[WebMethod]Step 2.
public System.Object HelloWorld()
{
string s = "Hello World";
return (object)s;
}
set it to WSRF and WSE3.0
Step 3.
invoke WSRF PAT tool
Trouble shooting:
1. we must have a namespace for the service.cs else WSRF will have trouble. (A bug ?)
2. sometimes it does not work, simple change in the service.asmx file class=xxx.NAMESPACE.CLASS to class=NAMESPACE.CLASS
and remove the xxxGenerated.cs file
3. If WSRF option does not show up in the property windows of service.asmx file
then rebuild the WSRF.NET common lib project
then rebuild the Add-in project
restart VS 2005.
Step 4.
Get xxxPortType.wsdl in C:\Inetpub\wwwroot\
Remove all the occurrence of
type="tns:Object"
Or replace it to
type="xsd:anyType"
change element name from Object to anyType in favor of ASP.NET
update your web reference for the new wsdl file
and in your client you can call it as
cliMain.localhost.testService s = new cliMain.localhost.testService();
cliMain.localhost.HelloWorld h=new cliMain.localhost.HelloWorld();
object o = s.HelloWorld(h).HelloWorldResult;
Console.Out.WriteLine((string)o);