473,326 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

This works, but should it?

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?
Nov 16 '05 #1
1 1093
Greg,

This is actually how you have to do this. The reason is that when VS
generates the WDSL, and you subsequently generate the proxy, it doesn't know
about your type residing on the server. However, it can construct a new
type definition based on the WDSL, and that is what it does. Unfortunately,
this doesn't mean that they are the same type.

I believe that the web method doesn't use fully qualified type names, so
you should be able to place a using statement at the top of the proxy in
order to have it use your type instead of the imported type.

Other than that though, this is the way that you would have to handle
this situation.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Greg Merideth" <gm**************@this.forwardtechnology.net> wrote in
message news:9L********************@comcast.com...
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?

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andy Stevenson | last post by:
Hi, As subject, I have the following JS in my HTML document & it works fine: <SCRIPT type="text/JavaScript"> <!-- COPYRIGHT = " : Copyright &copy; Diverse Arts., 2003-"; function...
2
by: deko | last post by:
Has anyone been able to import data from Claris Works into Access 2002? Is it simply a matter of exporting the Claris Works data into a comma delimited file and mapping the fields? Thanks in...
6
by: Ook | last post by:
I've given up on MySQL for now - and just built a basic c# dotnet asp web app. It works. However, if I try to view the app in a non-Microsoft browser, it doesn't do anything. Specifically, I'm...
3
by: Steve Yerkes | last post by:
There seems to be way too much confusion over how to set focus on the a field using a field validator. I looked all over the web and found people trying to do this, but not getting anywhere. There...
9
by: ani | last post by:
I have been posting this question for the past 2 weeks and there wasn't any response. I really don't understand why I am not getting any responses. Does my question sound very stupid? Anyway, here...
10
by: sara | last post by:
I have been volunteered to write a simple system to help a non-profit enter and track information on the elders they serve. (It's actually a fascinating activity, and very rewarding to be helping...
4
by: Summercoolness | last post by:
does anyone know why this CSS works in IE 7 but not Firefox or Safari? (it works weird in Firefox and Safari) <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://...
8
by: The Natural Philosopher | last post by:
This is so weird. What I am trying to do is to upload files and stuff them in a mysql database. Everything works except the file content is zero. using the load_file command from mysql...
69
by: Bill Reid | last post by:
This is how I handle a check that the last character of a text file is a newline: /* checks if newline is last character of text file */ unsigned check_text_file_newline_termination(FILE...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.