[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Dino Chiesa [Microsoft]

6/1/2004 9:55:00 PM



"Russ" <russk2@eticomm.net> wrote in message
news:broeb0duam423u01hfio2jj11vrausliel@4ax.com...
> 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



3 Answers

Russ

6/1/2004 10:57:00 PM

0

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


On Tue, 1 Jun 2004 15:55:03 -0400, "Dino Chiesa [Microsoft]"
<dinoch@online.microsoft.com> wrote:

>
>
>"Russ" <russk2@eticomm.net> wrote in message
>news:broeb0duam423u01hfio2jj11vrausliel@4ax.com...
>> 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
>
>

Dino Chiesa [Microsoft]

6/2/2004 9:22:00 PM

0

> 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

Maybe you figured this out by now but....that GetEmployeeInfo method is
exposed in the WSDL, which is the interface definition. When you build the
client, you run wsdl.exe (or "Add Web Ref") and the client-side proxy class
that is generated includes a definition for MyClass.



Russ

6/2/2004 11:53:00 PM

0

Yes, I did figure it out. Thanks much for your help.

Russ

On Wed, 2 Jun 2004 15:22:15 -0400, "Dino Chiesa [Microsoft]"
<dinoch@online.microsoft.com> wrote:

>> 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
>
>Maybe you figured this out by now but....that GetEmployeeInfo method is
>exposed in the WSDL, which is the interface definition. When you build the
>client, you run wsdl.exe (or "Add Web Ref") and the client-side proxy class
>that is generated includes a definition for MyClass.
>
>