Data transfer

R

Russ

I'm still very new to .NET. I managed to write a web service using
managed extensions for C++ and integrate it with existing business
logic. The web client is written in C#. To receive bunch of strings
from the server, the client does this:

String [] n = ws.GetEmployeeInfo (empno);
Name.Text = n [0];
Department.Text = n [1];
Type.Text = n [2];
Period.Text = n [3];
PayType.Text = n [4];
PayRate.Text = n [5];
CheckDate.Text = n [6];

This works, but now I need to retrieve more hetrogeneous data. What I
would like to do is create a class and pass it from the service to the
client (and vice versa at times). So the code would then look more
like:

MyClass data = ws.GetEmployeeInfo (empno);
Name.Text = data.Name;
Department.Text = data.Dept;

etc, and then I could have other data types in the class such as bool
and double..

My problem is how does the C++ service and the C# client each know
what the class looks like? Is there a way to put the class definition
in a header file and include it in both sources? I realize that the
data is passed via XML and so the field names and types are passed,
but again, how do I tell the server to use a class that the client
will understand?

I have tried to understand the concept of a dataset and see if it
could be used, but it incapsulates way more functionality than I need,
and I still don't see how the C++ web service can know what it looks
like, and how to fill it. This data does not come out of a relational
database, so using SQL, OleDB and OBDC does not make any sense (at
least to me).

Thanks for any help.

Russ
 
D

Dino Chiesa [Microsoft]

Russ said:
I'm still very new to .NET. I managed to write a web service using
managed extensions for C++ and integrate it with existing business
logic. The web client is written in C#. To receive bunch of strings
from the server, the client does this:

String [] n = ws.GetEmployeeInfo (empno);
Name.Text = n [0];
Department.Text = n [1];
Type.Text = n [2];
Period.Text = n [3];
PayType.Text = n [4];
PayRate.Text = n [5];
CheckDate.Text = n [6];

This works, but now I need to retrieve more hetrogeneous data. What I
would like to do is create a class and pass it from the service to the
client (and vice versa at times). So the code would then look more
like:

MyClass data = ws.GetEmployeeInfo (empno);
Name.Text = data.Name;
Department.Text = data.Dept;

In C#, I would code a webmethod that does this, like so:

public class MyClass {
public string Name;
public int Dept;
public bool Verified;
public AnotherClass[] ArrayOfSomething;
// etc....
}

[WebService]
public class MyService {
[webMethod]
public MyClass GetEmployeeInfo(int empno) {
....
}
}

Sorry I don't know the C++ syntax.

My problem is how does the C++ service and the C# client each know
what the class looks like? Is there a way to put the class definition
in a header file and include it in both sources?

Yes, such classes as are used in the webservice are included in the WSDL
(Webservices Definition Language), which is like an IDL (Interface
Definition language) file if you know CORBA or DCE. For the client-proxy
generation, you run "Add Web Reference" in visual studio, or you run
wsdl.exe if you develop with just the .NET SDK. You pass in the WSDL to
either of these, and the output is a client proxy, complete with a generated
version of "MyClass".


how do I tell the server to use a class that the client
will understand?

You don't. You generate a class for use within the client according to the
published interface (the WSDL).

maybe this will help?

-Dino
 
R

Russ

Dino, thanks for your response. Having had the long holiday weekend
to mull it over I had come to the conclusion that I should try
something about like you showed. So I will try it and see if it
works. The only part that confuses me is in the client, where you do:
public MyClass GetEmployeeInfo(int empno) {

How does the client C# code know what MyClass looks like? I guess
this is some magic of the SOAP protocol, but I know that in C++ if I
tried to do that without declaring and defining the class first, I
would get a compile error.

Still, I will try it shortly (and report back here if I still cannot
make it work.)

Trying to learn about web programming AND C# at the same time is a
bear...

Thanks again, Russ


Russ said:
I'm still very new to .NET. I managed to write a web service using
managed extensions for C++ and integrate it with existing business
logic. The web client is written in C#. To receive bunch of strings
from the server, the client does this:

String [] n = ws.GetEmployeeInfo (empno);
Name.Text = n [0];
Department.Text = n [1];
Type.Text = n [2];
Period.Text = n [3];
PayType.Text = n [4];
PayRate.Text = n [5];
CheckDate.Text = n [6];

This works, but now I need to retrieve more hetrogeneous data. What I
would like to do is create a class and pass it from the service to the
client (and vice versa at times). So the code would then look more
like:

MyClass data = ws.GetEmployeeInfo (empno);
Name.Text = data.Name;
Department.Text = data.Dept;

In C#, I would code a webmethod that does this, like so:

public class MyClass {
public string Name;
public int Dept;
public bool Verified;
public AnotherClass[] ArrayOfSomething;
// etc....
}

[WebService]
public class MyService {
[webMethod]
public MyClass GetEmployeeInfo(int empno) {
....
}
}

Sorry I don't know the C++ syntax.

My problem is how does the C++ service and the C# client each know
what the class looks like? Is there a way to put the class definition
in a header file and include it in both sources?

Yes, such classes as are used in the webservice are included in the WSDL
(Webservices Definition Language), which is like an IDL (Interface
Definition language) file if you know CORBA or DCE. For the client-proxy
generation, you run "Add Web Reference" in visual studio, or you run
wsdl.exe if you develop with just the .NET SDK. You pass in the WSDL to
either of these, and the output is a client proxy, complete with a generated
version of "MyClass".


how do I tell the server to use a class that the client
will understand?

You don't. You generate a class for use within the client according to the
published interface (the WSDL).

maybe this will help?

-Dino
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top