Custom classes with web services

C

Chris Dunaway

I have a custom class called User with fields like Name, Address, etc.
This is compiled into a .dll.

I also have a Windows app that will reference a couple of web services.

Both the Windows app and the Webservices will use this User class.

Each web service references the .dll to get the user class. My Windows app
also references the .dll to get the User class.

My problem arises when I reference the web services. I can reference them
ok but they each have their own version of the User class! Further, they
are not compatible.

For example, my .dll with the User class has a namespace of MyNamespace and
the two web services are as follows:

Authenticate.asmx references the .dll and has the following method:

Imports MyNamespace

<WebMethod> _
Public Function Login(usr as String, pwd As String) As User
End Function


MainWebService.asmx also references the .dll has the folowing method:

Imports MyNamespace

<WebMethod> _
Public Sub Process(usr As User)
End Sub

All seems OK but when I reference both web services from my windows App, I
get two 'extra' User classes. I want to call them this way:

Public Sub CallWebServices()
Dim oAuth As New Authenticate
Dim oMain As New MainWebService
Dim oUsr As MyNamespace.User

oUsr = oAuth.Login("user","password")
'The line above fails stating that an object of type MyNamespace.User
'cannot be converted to an object of type Authenticate.User
'If I use the following:

Dim oUsr2 As Authenticate.User
oUsr2 = oAuth.Login("user", "password")
'The above seems to work OK but then the following line fails saying
'An object of type Authenticate.User cannot be converted to
'MainWebService.User

oMain.Process(oUsr2) 'This fails

End Sub

I can change the Reference.vb files for each web service to use the correct
user class (the one in MyNamespace) but if I update the web service then
the changes will be lost.

How can I use a custom class in a Windows App that references a web service
and have the web service return the correct types?

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
D

Dan Rogers

Hi Chris,

What you are experiencing is the automatic behavior of the generated proxy.
What you need to do is work with a modified proxy, as you have discovered,
or serialize to XML as the means to move data between your classes. The
proxy is an assembly that is generated as a part of the project where you
do an add-web-reference. The way I recommend you work with this is to open
the proxy code - no need to change references, per se. Just comment out
the additional copy of the classes in question in the code for the proxy
class, and then add a "imports" statement for your custom DLL namespace at
the top of that file. This should make the proxy actually use your shared
DLL rather than the projection that is created by reading the WSDL file
from the web service.

As far as changing your web service, this is possibly an area that you want
to think about. If changes to your web service break the interface to your
existing clients, then perhaps you are still very early on in development.
In a production environment, you typically won't have the luxury of
breaking an unknown number of callers - so I would suggest that this is a
cost of dealing with an early-on stage in development where it is normal to
be futzing around with the members of your classes and method interfaces.

I hope this helps,

Dan Rogers
Microsoft Corporation


--------------------
From: Chris Dunaway <"dunawayc[[at]_lunchmeat_sbcglobal[dot]]net">
Subject: Custom classes with web services
User-Agent: 40tude_Dialog/2.0.10.1
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Date: Wed, 1 Dec 2004 11:33:25 -0600
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
NNTP-Posting-Host: 216.143.212.98
Lines: 1
Path: cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13
.phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.aspnet.webservices:26941
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices

I have a custom class called User with fields like Name, Address, etc.
This is compiled into a .dll.

I also have a Windows app that will reference a couple of web services.

Both the Windows app and the Webservices will use this User class.

Each web service references the .dll to get the user class. My Windows app
also references the .dll to get the User class.

My problem arises when I reference the web services. I can reference them
ok but they each have their own version of the User class! Further, they
are not compatible.

For example, my .dll with the User class has a namespace of MyNamespace and
the two web services are as follows:

Authenticate.asmx references the .dll and has the following method:

Imports MyNamespace

<WebMethod> _
Public Function Login(usr as String, pwd As String) As User
End Function


MainWebService.asmx also references the .dll has the folowing method:

Imports MyNamespace

<WebMethod> _
Public Sub Process(usr As User)
End Sub

All seems OK but when I reference both web services from my windows App, I
get two 'extra' User classes. I want to call them this way:

Public Sub CallWebServices()
Dim oAuth As New Authenticate
Dim oMain As New MainWebService
Dim oUsr As MyNamespace.User

oUsr = oAuth.Login("user","password")
'The line above fails stating that an object of type MyNamespace.User
'cannot be converted to an object of type Authenticate.User
'If I use the following:

Dim oUsr2 As Authenticate.User
oUsr2 = oAuth.Login("user", "password")
'The above seems to work OK but then the following line fails saying
'An object of type Authenticate.User cannot be converted to
'MainWebService.User

oMain.Process(oUsr2) 'This fails

End Sub

I can change the Reference.vb files for each web service to use the correct
user class (the one in MyNamespace) but if I update the web service then
the changes will be lost.

How can I use a custom class in a Windows App that references a web service
and have the web service return the correct types?

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
C

Chris Dunaway

As far as changing your web service, this is possibly an area that you want
to think about. If changes to your web service break the interface to your
existing clients, then perhaps you are still very early on in development.

Thanks for the response. Yes, we are early in development. I was mainly
trying to alleviate frustrations in development because it is a pain to
have to change the generated proxy class. Once the web service is
completed and "live" then we will not change it, or at least not change the
interface to it. It is mainly during development that this is causing us a
headache.

Thanks again.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
D

Dan Rogers

Hi Chris,

During development, I think it's safe to say that if you change the
interface, you should refresh the proxy. Since each caller has it's own
instance of the proxy (typically), you may want to make refreshing the
proxy a normal practice if calls that used to work no longer work. Either
that, or make your proxy a factor of the web service project and that your
clients bind to directly. This way if you change the service, you change
the proxy, and everyone picks up the changes. Not that all changes will be
code compatible, but it's a thought.

Regards

Dan Rogers
Microsoft Corporation
--------------------
From: Chris Dunaway <"dunawayc[[at]_lunchmeat_sbcglobal[dot]]net">
Subject: Re: Custom classes with web services
User-Agent: 40tude_Dialog/2.0.10.1
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
References: <[email protected]>
Date: Wed, 1 Dec 2004 17:17:33 -0600
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
NNTP-Posting-Host: 216.143.212.98
Lines: 1
Path: cpmsftngxa10.phx.gbl!TK2MSFTFEED02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11
.phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.aspnet.webservices:26971
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices

As far as changing your web service, this is possibly an area that you want
to think about. If changes to your web service break the interface to your
existing clients, then perhaps you are still very early on in
development.

Thanks for the response. Yes, we are early in development. I was mainly
trying to alleviate frustrations in development because it is a pain to
have to change the generated proxy class. Once the web service is
completed and "live" then we will not change it, or at least not change the
interface to it. It is mainly during development that this is causing us a
headache.

Thanks again.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 

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,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top