G
Greg Merideth
I was looking for a way to pass, by reference, a class to a webmethod to allow
the web method to alter the values of some (now) 50 variables of the class.
Now, to get this to work, I have to put a copy of the class in the webmethod
itself. When I create the method I do the old:
public void mymethod(ref my_refclass)
however, when visual studio creates the proxy code it puts a reference to the
class of the webmethod (naturally) however visual studio then complains that
*my* local reference to the class cannot be done example:
client.cs
using Whatever.Webmethod;
class HelloClass { int a; } <---local
private void some func()
{
HelloClass _hello = new HelloClass();
webmethod web = new webmethod()
web.somefunc(ref _hello);
}
--
server.cs
class HelloClass { int a; } <---server
private HelloClass _hello = new HelloClass(); // or public, does the same thing
public void somefunc(ref _hello)
{
_hello.a = 10;
}
now, visual studio complains on the client that:
(client) HelloClass._hello cannot be matched against
Whatever.Webmethod.HelloClass._hello
Even thou they are the same class.. so what I did was go into the proxy code
generated by Visual studio and changed each method call in the proxy to point
to my local class. The upside is that now it works just fine, the webmethod
gets passed the entire empty class from the client and sends back the altered
values which get properly assigned to the clients class.
The problem is, this seems like a nasty hack method versus a "real" method of
doing it and everytime I load in or update the .asmx file I have to re-do the
changes and this hack wont work when I try it with the pocket PC build as the
proxy code created with pocket pc is different than a windows app build.
Anyone know if this is an accetable way of doing this or should I be looking
for other ways?
the web method to alter the values of some (now) 50 variables of the class.
Now, to get this to work, I have to put a copy of the class in the webmethod
itself. When I create the method I do the old:
public void mymethod(ref my_refclass)
however, when visual studio creates the proxy code it puts a reference to the
class of the webmethod (naturally) however visual studio then complains that
*my* local reference to the class cannot be done example:
client.cs
using Whatever.Webmethod;
class HelloClass { int a; } <---local
private void some func()
{
HelloClass _hello = new HelloClass();
webmethod web = new webmethod()
web.somefunc(ref _hello);
}
--
server.cs
class HelloClass { int a; } <---server
private HelloClass _hello = new HelloClass(); // or public, does the same thing
public void somefunc(ref _hello)
{
_hello.a = 10;
}
now, visual studio complains on the client that:
(client) HelloClass._hello cannot be matched against
Whatever.Webmethod.HelloClass._hello
Even thou they are the same class.. so what I did was go into the proxy code
generated by Visual studio and changed each method call in the proxy to point
to my local class. The upside is that now it works just fine, the webmethod
gets passed the entire empty class from the client and sends back the altered
values which get properly assigned to the clients class.
The problem is, this seems like a nasty hack method versus a "real" method of
doing it and everytime I load in or update the .asmx file I have to re-do the
changes and this hack wont work when I try it with the pocket PC build as the
proxy code created with pocket pc is different than a windows app build.
Anyone know if this is an accetable way of doing this or should I be looking
for other ways?