Professional Web Applications Themes

Custom classes with web services - ASP.NET Web Services

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, ...

  1. #1

    Default Custom classes with web services

    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.
    Chris Dunaway Guest

  2. #2

    Default RE: Custom classes with web services

    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; cht="us-ascii"
    >Content-Transfer-Encoding: 7bit
    >Date: Wed, 1 Dec 2004 11:33:25 -0600
    >Message-ID: <1vdp14koua85a.g1bp8fgo9ojk.dlg40tude.net>
    >Newsgroups: microsoft.public.dotnet.framework.aspnet.webservic es
    >NNTP-Posting-Host: 216.143.212.98
    >Lines: 1
    >Path:
    cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFT NGP08.phx.gbl!tk2msftngp13
    .phx.gbl
    >Xref: cpmsftngxa10.phx.gbl
    microsoft.public.dotnet.framework.aspnet.webservic es:26941
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
    >
    >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.
    >
    Dan Rogers Guest

  3. #3

    Default Re: Custom classes with web services

    On Wed, 01 Dec 2004 19:38:44 GMT, Dan Rogers wrote:
    > 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.
    Chris Dunaway Guest

  4. #4

    Default Re: Custom classes with web services

    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; cht="us-ascii"
    >Content-Transfer-Encoding: 7bit
    >References: <1vdp14koua85a.g1bp8fgo9ojk.dlg40tude.net>
    <ihlWi191EHA.3820cpmsftngxa10.phx.gbl>
    >Date: Wed, 1 Dec 2004 17:17:33 -0600
    >Message-ID: <7tl3kq2rt054$.1ups2kl6j90gx.dlg40tude.net>
    >Newsgroups: microsoft.public.dotnet.framework.aspnet.webservic es
    >NNTP-Posting-Host: 216.143.212.98
    >Lines: 1
    >Path:
    cpmsftngxa10.phx.gbl!TK2MSFTFEED02.phx.gbl!TK2MSFT NGP08.phx.gbl!TK2MSFTNGP11
    .phx.gbl
    >Xref: cpmsftngxa10.phx.gbl
    microsoft.public.dotnet.framework.aspnet.webservic es:26971
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
    >
    >On Wed, 01 Dec 2004 19:38:44 GMT, Dan Rogers wrote:
    >
    >> 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.
    >
    Dan Rogers Guest

Similar Threads

  1. casting custom classes
    By Sam in forum ASP.NET Building Controls
    Replies: 2
    Last Post: July 27th, 09:50 AM
  2. custom types: classes
    By Chris in forum ASP.NET Web Services
    Replies: 5
    Last Post: June 24th, 05:55 PM
  3. Events in Custom Controls and Sub Classes
    By Reiner Max in forum ASP.NET Building Controls
    Replies: 1
    Last Post: June 15th, 12:14 PM
  4. Creating custom classes
    By Pea in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: March 4th, 07:14 AM
  5. Custom Classes with loadmovie, help!
    By The dedicated lad webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 2
    Last Post: February 5th, 10:25 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139