473,854 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

return non-dataset XML to vb.net client?

(I posted this in languages.vb also... I can't figure out where things go if
you use a little of a lot of things)

Hi all... I'm looking for an example (or a pointer to one) related to the
following. I have a WebService (it works) that fetches data, turns it into
XML and returns it to a vb.net client. The "data" though represents
property values for an object which the vb.net client has created and now
has to load.

Just about every example I have found demonstrates how "tables, rows,
columns" and such can be fetched, updated, etc. but I have it working so
that nothing on the client side knows a thing about where the data comes
from or if it is even fetched from a table at all. It is all objects (and
collections of objects) on the client side.

So the XML string that has to be created on the server is a mix of things.
It includes data from one or more tables but also the result of some other
"knowledge" that it has (the date and time on the server for instance). The
XML returned will be a composite of the properties that make up the object.

I'm looking for a way to cleanly create this composite XML string on the
server side and an equally elegant way to break it down again on the client
so the values can be assigned to the newly created object. Any ideas?

I have it all working with VB6, DCOM and property bags but I'd like to get
it all converted to .NET before the decade is out :-) A website, an
article, a book, I'll take what I can get.

Thanks,
Tom

Jul 21 '05 #1
11 1956
ick
Tom,

I don't really get why you are sending XML ?
If you are just going to create objects on the client side, why not send
objects?

Eg, make a webservice that returns a custom type , and return that type.

Then on the client side, the response is an instance of that type.

In other words, the .NET runtime takes care of serialization and
de-serialization of the object graph into (and from) XML. XML is used on
the wire but you don't need to interact with XML or the DOM within your
applicaiton logic.

You do this:
server side:
create object graph
send it as a response
client side:
get response object
do work on it. .. . .
Does this work??

------

On the other hand if you send and receive XML, then in effect you would be
doing this within your application:
server side:
create your object graph
serialize it to XML
send that string to client
client side:
get xml string
de-serialize it (manually??!) into an object graph
do work on it...

This seems like you are doing more work that you need to...

If you really insist on doing the serialization yourself, then you could do
this (sorry, not VB):

server side:

[WebMethod]
public string GetRawXml()
{
System.Xml.XmlD ocument doc = new System.Xml.XmlD ocument();
MyCustomType instance= new MyCustomType ();
// fill MyCustomType here.... (fill in the object graph)

System.IO.Strin gWriter sw = new System.IO.Strin gWriter();
System.Xml.Seri alization.XmlSe rializer s1 = new
System.Xml.Seri alization.XmlSe rializer(typeof (MyCustomType)) ;
s1.Serialize(sw , instance);
return sw.ToString();
}

client side:

string s= MyWebService.Ge tRawXml();
System.Xml.XmlD ocument doc= new System.Xml.XmlD ocument();
doc.LoadXml(s);
// here, you would manually construct the object graph from the given
XmlDocument
// then, do some work on the object graph
--
Dino Chiesa
Microsoft Developer Division
d i n o c h @ o n l i n e . m i c r o s o f t . c o m

"Tom Leylan" <ge*@iamtiredof spam.com> wrote in message
news:T7******** ***********@twi ster.nyc.rr.com ...
(I posted this in languages.vb also... I can't figure out where things go if you use a little of a lot of things)

Hi all... I'm looking for an example (or a pointer to one) related to the
following. I have a WebService (it works) that fetches data, turns it into XML and returns it to a vb.net client. The "data" though represents
property values for an object which the vb.net client has created and now
has to load.

Just about every example I have found demonstrates how "tables, rows,
columns" and such can be fetched, updated, etc. but I have it working so
that nothing on the client side knows a thing about where the data comes
from or if it is even fetched from a table at all. It is all objects (and
collections of objects) on the client side.

So the XML string that has to be created on the server is a mix of things.
It includes data from one or more tables but also the result of some other
"knowledge" that it has (the date and time on the server for instance). The XML returned will be a composite of the properties that make up the object.
I'm looking for a way to cleanly create this composite XML string on the
server side and an equally elegant way to break it down again on the client so the values can be assigned to the newly created object. Any ideas?

I have it all working with VB6, DCOM and property bags but I'd like to get
it all converted to .NET before the decade is out :-) A website, an
article, a book, I'll take what I can get.

Thanks,
Tom

Jul 21 '05 #2
"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote...
I don't really get why you are sending XML ?
If you are just going to create objects on the client side, why not send
objects?
Hi Dino... Can I be your friend :-) I started using XML because I thought
that was the way to do it. It currently works (in VB6) with a byte stream
and I'm happy with that but I'll always listen to a better idea.
Eg, make a webservice that returns a custom type , and return that type.
Then on the client side, the response is an instance of that type.

In other words, the .NET runtime takes care of serialization and
de-serialization of the object graph into (and from) XML. XML is used on
the wire but you don't need to interact with XML or the DOM within your
applicaiton logic.

You do this:
server side:
create object graph
send it as a response
client side:
get response object
do work on it. .. . .

Does this work??


It works for me! My current implementation converted to strings to make the
transmission faster but if that is what .NET is going to do anyway I'd love
to let .NET handle the details.

(I always look this stuff in the interim but...) is there any way you can
point me to an example of what my class has to do in order to give it this
ability to self-serialize? I learn fast but I seem to "search" rather slow.
Maybe the problem is when I get 1,900,000 hits :-)

Thanks,
Tom

Jul 21 '05 #3
"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote...

Dino... I found some articles on serialization and formatters. I have to
read more about this now as it looks exactly like what I was intending to
do.

Also do you have any opinions on whether it's (generally speaking)
worthwhile to put it in a soap wrapper at this point? I'm not going to
offer the data through the Internet or to the general public but it might
make for an interesting demo to a client and if there isn't much downside it
might be a good thing.

Thanks,
Tom


Jul 21 '05 #4
"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote...

Hi again Dino, well this has been interesting. I just read about the
ISerializable interface and I believe I'll add the extra code to go that
route.

It seems to me to offer a little more control and... one of the things
(unless I'm mistaken) I will have to set up is a separate "data-aware"
class. This MgrClass would have a method for returning the class I want,
and a method that accepts a serialized version of my class (passed back) for
storage. As I see it, if I don't do it this way then any ADO (along with
any other data-related "SQL" for instance) references need to be compiled
into the client side.

Those methods for fetching and saving data make no sense in the client-side
version of the object since it can't access the database (that's all done on
the server.) And the client-side versions make no sense in the server
version.

Does this make sense or have I over-complicated it again? BTW, the samples
I've found so far use "cloning" an object as the example. The requirements
for creating a local copy are different than when sending one across a wire
to another machine. In those cases (as I've mentioned) they can't be
_exact_ duplicates unless all the capabilities are compiled into both the
server and the client and that's not a great idea.

Thanks for your comment,
Tom


..
Jul 21 '05 #5
Hey Tom, you've been busy!

1. re: ISerializable
Can we start with something simple? I am not sure of your requirements, so
maybe we can start with the simpler cases and work up to the more complex
ones (like using ISerializable).

You can get implicit serialization with .NET and web services.
ISerializable gives you more control but are you sure you want and need it?
You may be able to get by with the implicit xml-serialization support in
..NET.

Here's source code for an example service, and client, and makefile. This
example exhibits both manual serialization (sending response as a string),
and auto-magic serialization (Sending the actual object, which gets
automatically serialized as xml), of complex types.
http://cheeso.europe.webmatrixhostin...e=Service.asmx

Here's the URL for the (working) service:
http://cheeso.europe.webmatrixhostin...n/Service.asmx

You can try it out via the test form.

Here's a great intro article on XML and serialization in .NET:
http://www.agiledeveloper.com/articl...ialization.pdf

2. re: SOAP Wrapper
YES, use web services. If your load and performance requirements allows you
to use XML as the on-the-wire protocol, then by all means use web services
and expose the service via SOAP. Even if you don't expose it over the
internet publicly, this is the way to do it. Why? Because web services
allows maximum interop - clients regardless of platform or technology will
be able to consume your service. It's the most flexible method, and the
tools support is great. Also this is where the strategic development is
happening within Microsoft and within the broader industry.
-Dino
"Tom Leylan" <ge*@iamtiredof spam.com> wrote in message
news:DS******** ***********@twi ster.nyc.rr.com ...
"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote...

Hi again Dino, well this has been interesting. I just read about the
ISerializable interface and I believe I'll add the extra code to go that
route.

It seems to me to offer a little more control and... one of the things
(unless I'm mistaken) I will have to set up is a separate "data-aware"
class. This MgrClass would have a method for returning the class I want,
and a method that accepts a serialized version of my class (passed back) for storage. As I see it, if I don't do it this way then any ADO (along with
any other data-related "SQL" for instance) references need to be compiled
into the client side.

Those methods for fetching and saving data make no sense in the client-side version of the object since it can't access the database (that's all done on the server.) And the client-side versions make no sense in the server
version.

Does this make sense or have I over-complicated it again? BTW, the samples I've found so far use "cloning" an object as the example. The requirements for creating a local copy are different than when sending one across a wire to another machine. In those cases (as I've mentioned) they can't be
_exact_ duplicates unless all the capabilities are compiled into both the
server and the client and that's not a great idea.

Thanks for your comment,
Tom


.

Jul 21 '05 #6
"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote...
Hey Tom, you've been busy!
As apparently have you :-)
Can we start with something simple? I am not sure of your requirements, so maybe we can start with the simpler cases and work up to the more complex
ones (like using ISerializable).
On rethought it looks like the default system will work fine. Your examples
were great... crazy for all the data-generating detail <g> but great. And
I've saved the article you mentioned.
2. re: SOAP Wrapper


That's pretty much what I was thinking also. Requirements never "shrink"
and they always expand outside of what is defined as 'the most we'll ever
need" typically before we're done programming it.

I'm going to incorporate all of this now that I am certain it will work.
And thanks again very much for your lucid explanations. It shows us that
newsgroups don't have to be just a series of people posting "you're a dope"
(or worse) at each other.

Tom
Jul 21 '05 #7
"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote...

Dino... aw shucks there is a problem. I tried all sorts of combinations but
nothing works. Your example creates a class defined in the web service and
uses it in the web service but it doesn't create an object on a client
elsewhere.

When I debug my web service project I see the code execute and it serializes
my object and it creates the XML just fine. When I then go to my client (in
this case a .DLL) it says it can't create an object from the class on the
server.

My biggest problem is deciding where and how to define the class itself. I
sort of alluded to the problem in an earlier message but I probably didn't
state it clearly. In fact I know I goofed up on the description a bit.

On the client-side there is a .DLL which contains business objects (let's
call it MYDATA.DLL. A client app would access MYDATA.DLL of course. Let's
call one of the classes "Customer." I've declared it to be serializable.
The web service obviously needs to be able to instantiate an object of type
Customer also in order to fill it with data and to send it MYDATA.DLL on the
client side. My first thought was to give the MYSERVICE.ASPX project a
reference to MYDATA.DLL so they are using a common Customer class.
MYSERVICE.ASPX has a GetCustomer service available which will return a
serialized Customer object. As I mentioned this works when testing
MYSERVICE.

When I then try to access the class (in the debugger) using MYDATA.DLL by
calling a Test() function which instantiates a Customer object and then
requests the object from MYSERVICE it won't compile or run complaining that
the two versions of Customer are incompatible.

The error doesn't exactly indicate it but I thought the problem might be
that both my test and the web service want the same copy of the .DLL since
I'm testing on a localserver. This wouldn't be the case if I put a copy out
on the Internet of course but that makes testing more difficult.

One thought I had was to create a .DLL with the business classes separate
from the one that fetches the data. That way the business class .DLL would
be part of the web service project but the data fetching .DLL wouldn't. If
there is a conflict created by the one shared .DLL doing all the work this
should stop that. But I don't know if it would make a difference.

Any idea? Do you need a better description?

I think the bottom line question is how do web services and clients get
access to a common class definition?

Thanks,
Tom
Jul 21 '05 #8
"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote...
Hey Tom, you've been busy!


And I've been busy again, too. I have more information. I'm probably going
to have to implement remoting. I just read an article on the MS site that
outlined the differences (and ties) between web services and remoting. It
defined a number of issues with the return of some classes when a web
service returns it's idea of what the properties of a class are. Computed
properties aren't returned for instance and the client won't even know they
were supposed to exist.

It also looks fairly straightforward to set up a customized server (in place
of using IIS) if one wanted to direct the exchange to another port or wanted
to set up some special features. It cleared up my confusion about where the
..DLL goes also. In the case of web services on the server, in the case of
remoting both on the server and the client.

Well I have something to keep me occupied through Friday now!

Tom

Jul 21 '05 #9
Tom, I think you are describing the situation covered in these articles:

http://msdn.microsoft.com/library/en...ce08202002.asp
http://msdn.microsoft.com/library/en...ce07162002.asp

They offer hints on how to generate data types from XSD and share them
across webservices clients and servers.

"Tom Leylan" <ge*@iamtiredof spam.com> wrote in message
news:zZ******** **************@ twister.nyc.rr. com...
"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote...

Dino... aw shucks there is a problem. I tried all sorts of combinations but nothing works. Your example creates a class defined in the web service and uses it in the web service but it doesn't create an object on a client
elsewhere.

When I debug my web service project I see the code execute and it serializes my object and it creates the XML just fine. When I then go to my client (in this case a .DLL) it says it can't create an object from the class on the
server.

My biggest problem is deciding where and how to define the class itself. I sort of alluded to the problem in an earlier message but I probably didn't
state it clearly. In fact I know I goofed up on the description a bit.

On the client-side there is a .DLL which contains business objects (let's
call it MYDATA.DLL. A client app would access MYDATA.DLL of course. Let's call one of the classes "Customer." I've declared it to be serializable.
The web service obviously needs to be able to instantiate an object of type Customer also in order to fill it with data and to send it MYDATA.DLL on the client side. My first thought was to give the MYSERVICE.ASPX project a
reference to MYDATA.DLL so they are using a common Customer class.
MYSERVICE.ASPX has a GetCustomer service available which will return a
serialized Customer object. As I mentioned this works when testing
MYSERVICE.

When I then try to access the class (in the debugger) using MYDATA.DLL by
calling a Test() function which instantiates a Customer object and then
requests the object from MYSERVICE it won't compile or run complaining that the two versions of Customer are incompatible.

The error doesn't exactly indicate it but I thought the problem might be
that both my test and the web service want the same copy of the .DLL since
I'm testing on a localserver. This wouldn't be the case if I put a copy out on the Internet of course but that makes testing more difficult.

One thought I had was to create a .DLL with the business classes separate
from the one that fetches the data. That way the business class .DLL would be part of the web service project but the data fetching .DLL wouldn't. If there is a conflict created by the one shared .DLL doing all the work this
should stop that. But I don't know if it would make a difference.

Any idea? Do you need a better description?

I think the bottom line question is how do web services and clients get
access to a common class definition?

Thanks,
Tom

Jul 21 '05 #10

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

Similar topics

19
2812
by: Christian Engström | last post by:
If you have a function that returns something by value, the gcc compiler (version 3.2.3 on Windows XP with MinGW) converts the returned value from the type you specify in the code, to the const version of that type. Is this a bug that is specific to gcc, or is it a flaw in the language specification that gcc diligently implements? For example, the below program produces the output Constant Mutable
5
3765
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence their dtor is called immediately and not at the end of the function. to be able to use return objects (to avoid copying) i often assign them to a const reference. now, casting a const return object from a function to a non-const reference to this...
3
1690
by: red floyd | last post by:
Once again, I'm fighting a port from the (allegedly standard compliant) VC7.1 to G++. VC compiles this, G++ doesn't. Am I allowed to pass the anonymous temporary returned by f() to a function requiring a non-const reference? I suspect G++ is correct, and VC is (again) braindead.
3
1700
by: Matt | last post by:
Hello, I'm trying to implement the design below. I'd prefer to use commented operator+() in class Number instead of the associated, uncommented operator+(), but as I understand Covariant Return Types, one is not allowed to return non-references (eg, references or pointers) in virtual-functions (which seems to make sense given the seemingly polymorphic nature). So...I use the hack below and make my Object-return function be
15
6740
by: Greenhorn | last post by:
Hi, when a function doesn't specify a return type ,value what value is returned. In the below programme, the function sample()is returning the value passed to 'k'. sample(int); main() { int i = 0,j; j = sample(0);
3
5881
by: Eric the half a Bee | last post by:
Hello I am trying to implement a search function within a collection of Employees. I am searching for a specific EmpID number in the collection, and if it is found, I want to return the Employee. This I can do. The problem comes if the EmpID is not found in the collection. The only way to achieve this I can think of is to throw an invalid argument exception:
10
4955
by: Allerdyce.John | last post by:
Hi, I have a class with a STL vector as it attribute. How can I create a method which just return a 'read-only' view? (i.e. the caller of the function can only read the vector, not write it)? class A { private: vector<int> _v; public:
22
4055
by: semedao | last post by:
Hi , I am using asyc sockets p2p connection between 2 clients. when I debug step by step the both sides , i'ts work ok. when I run it , in somepoint (same location in the code) when I want to receive 5 bytes buffer , I call the BeginReceive and then wait on AsyncWaitHandle.WaitOne() but it is signald imidiatly , and the next call to EndReceive return zero bytes length , also the buffer is empty. here is the code: public static byte...
46
3881
by: Steven T. Hatton | last post by:
I just read §2.11.3 of D&E, and I have to say, I'm quite puzzled by what it says. http://java.sun.com/docs/books/tutorial/essential/concurrency/syncrgb.html <shrug> -- NOUN:1. Money or property bequeathed to another by will. 2. Something handed down from an ancestor or a predecessor or from the past: a legacy of religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF, from ML legatia, from L legare, to depute, bequeath....
9
3820
by: Francois Grieu | last post by:
When running the following code under MinGW, I get realloc(p,0) returned NULL Is that a non-conformance? TIA, Francois Grieu #include <stdio.h> #include <stdlib.h>
0
9901
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
9751
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
11024
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...
0
10371
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
5741
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
5941
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4560
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
2
4159
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3186
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.