473,654 Members | 3,062 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing strongly-typed datasets from WebService to C# consumer

Hi.

I've a single solution with many projects. I'm using VS2003 and framework 1.1

1. Data project - contains UserData class, inheriting from DataSet, and
setting up constants and columns like those found in the Duwamish 7 sample
2. WebServices project - wraps up business logic
3. C# winforms consumer connecting to the WebServices. This project has
the data project as a reference.

What I want to do (and what I'm sure I've done before) is to have a UserData
object. I've got a Login method on the webservice, which I want to return
this UserData object. I've got a WebMethod

[WebMethod]
public UserData GetUser(string username)
{
Users getUser = new Users();
return getUser.GetUser (username);
} //GetUser

OK - so far so good.

I've added the WebReference in the WinForms project for the user services.
However, it seems to have shoved a load of code in defining 'NewDataSet'.
This means that in my WinForms I've got (where 'user' is the webservice):

bool valid = false;
if ( user.Login(user name, password) )
{
UserData loginUser = user.GetUser(us ername);
valid = true;
}
return valid;

And I get an invalid cast beacuse even though in the webmethod I've
specified a return type of 'UserData', in the webreferece this has been
replaced with this reference to 'NewDataSet'!!!

In the WinForms code above, 'user.GetUser(u sername)' is defined as returning
'NewDataset' when I want it to be cast as 'UserData' as it is in the WS
source code.

How do I get the webservice to actually return the correct object?

Code on request.
Jul 10 '06 #1
1 2915
You cannot directly return any custom class from a web service and a
strongly-typed dataset is not a dataset, it's a custom class inherited from a
dataset.

You can work around the issue in several ways that will at least make it
relatively seamless to code, other than the workaround itself. I have a
series of articles that describe some solutions at
http://www.dalepreston.com/Blog/2005...-from-web.html.

HTH

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA
"ri***@newsgrou ps.nospam" wrote:
Hi.

I've a single solution with many projects. I'm using VS2003 and framework 1.1

1. Data project - contains UserData class, inheriting from DataSet, and
setting up constants and columns like those found in the Duwamish 7 sample
2. WebServices project - wraps up business logic
3. C# winforms consumer connecting to the WebServices. This project has
the data project as a reference.

What I want to do (and what I'm sure I've done before) is to have a UserData
object. I've got a Login method on the webservice, which I want to return
this UserData object. I've got a WebMethod

[WebMethod]
public UserData GetUser(string username)
{
Users getUser = new Users();
return getUser.GetUser (username);
} //GetUser

OK - so far so good.

I've added the WebReference in the WinForms project for the user services.
However, it seems to have shoved a load of code in defining 'NewDataSet'.
This means that in my WinForms I've got (where 'user' is the webservice):

bool valid = false;
if ( user.Login(user name, password) )
{
UserData loginUser = user.GetUser(us ername);
valid = true;
}
return valid;

And I get an invalid cast beacuse even though in the webmethod I've
specified a return type of 'UserData', in the webreferece this has been
replaced with this reference to 'NewDataSet'!!!

In the WinForms code above, 'user.GetUser(u sername)' is defined as returning
'NewDataset' when I want it to be cast as 'UserData' as it is in the WS
source code.

How do I get the webservice to actually return the correct object?

Code on request.
Jul 11 '06 #2

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

Similar topics

6
2289
by: Garma | last post by:
According to what I have learnt so far, instantiating global objects should be the last resort. Is there any reasons why so? Sometimes some objects or their pointers have to be shared among several other objects, I'd like to know how this is handled commonly. Could someone elaborate on this? Another situation is some objects could be shared among several threads. How to handle it commonly?
4
1454
by: SQLnewbie | last post by:
Wanted to know which among these options is better and why? Or if their could be scenarios where we could opt for one of these. a) flags passed from code to control the execution of queries within a stored procedure i.e. - where queries within a single stored procedure are controlled by flags passed to them. OR b) Break individual queries into separate stored procedure
4
4248
by: Vijai Kalyan | last post by:
I was decomposing a task into different policies. Essentially, there is a general option obtained from a server and user options obtained from configuration variables. The two options are complementary to one another. So I proceeded to decompose the tasks that deal with user options into two functions. Each of the functions do something and towards the end they do supplementary tasks that depend on the server option. The whole things...
5
1535
by: Oleg Subachev | last post by:
When I try to use strongly named assembly1 that references non-strongly named assembly2 I get the following error: "The located assembly '<assembly2 name>' is not strongly named." How can I force strongly named assembly1 to reference non-strongly named assembly2 ? --
1
358
by: jconnort | last post by:
I'm trying to write a function to get the current system time, so I can use it when I need to output it to a log, below is the code I'm testing: #include "include.h" #include <stdlib.h> main(argc, argv) int argc;
61
3122
by: academic | last post by:
When I declare a reference variable I initialize it to Nothing. Now I'm wondering if that best for String variables - is "" better? With Nothing I assume no memory is set aside nor GC'ed But with "" it is - correct? The system seems to handle a null the same as "".
1
2096
by: Vahehoo | last post by:
Hi, I have an ASP .Net e-business site that is built using DNN 2.0. I am having troubles passing my shopping cart items to PayPal. I implemented a total paynow button, but it was not good enough for my customer. I found some PayPal ASP.Net controls to be used with .net studio. Basically, I want the user to be able to shop on my website, add items to my shopping cart and at the checkout to be taken to the PayPal website. I would like...
5
1818
by: ephialtes | last post by:
Apologies for what will doubtless be a dim question. I'm using Dreamweaver to put together an online profiling app. The questions (really, a series of statements) come from a table called "profiling_questions" and I want to store the answers in a table called "profile_answers". The user is presented with a statement, and then has to click 'agree', 'strongly disagree', etc. - 6 possible outcomes. I want the new entry in 'profile_answers'...
2
3441
by: Bob Bruyn | last post by:
I've recently installed Apache 2 and php 5.2 on my WIndows XP machine. Everything is up and running. I'm passing some vars via the URL. It works fine online: http://www.torusdesign.nl/spry/test.php?folder=schilderijen/vrij_werk&navColor=SchilderijenNAV This is the code: <?php echo $folder; ?> <?php echo $navColor; ?>
0
1573
by: Dave Burns | last post by:
Hi, I have a C++ managed assembly (.dll) which links to a bunch of native libraries. Everything works fine if I don't make the managed assembly a strongly named one. Once I make it a strongly named assembly by adding the following attribute: ;
0
8375
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8482
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8593
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2714
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.