Results 1 to 9 of 9

Thread: Can I use web service to host my classes?

  1. #1

    Thread Starter
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Can I use web service to host my classes?

    My company uses a set of classes for every data access function. The bad part is distributing these dlls with every project that accesses a database. Is there a way to reference these classes in a web service, then have all the applications reference the web service to access the classes?
    Here's what I'm trying to do:
    VB Code:
    1. Dim WebServ1 as New WebService1
    2. Dim myClass1 as New WebServ1.MyClass1
    3. Dim myClass2 as New WebServ1.MyClass2

    Edit: I found this http://msdn.microsoft.com/library/de...SecNetHT15.asp
    Is remoting my only option?
    Last edited by wild_bill; Sep 11th, 2005 at 09:21 AM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Can I use web service to host my classes?

    Moved to ASP.NET.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Can I use web service to host my classes?

    No, it's actually very simple to use a web service for this. The classes you have for your data access and manipulation function can be referenced in your web service project.

    But it won't exactly be the way you're trying to do in your post. Instead you'll need to work with functions (called web methods in context of the web services) and work with the values being returned by it. For example, if you wish to return a class that you've created, you'll need to make sure its serializable. Else you can return the basic .NET types such as datasets, strings, integers, etc.

  4. #4

    Thread Starter
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Can I use web service to host my classes?

    Thanks for the reply. Is there a simple test to check if a class is serializable?

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Can I use web service to host my classes?

    If it is serializable, it'll have the <Serializable()> attribute in its definition

    http://www.c-sharpcorner.com/Code/20...ialization.asp

  6. #6

    Thread Starter
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Can I use web service to host my classes?

    Will I have to add WebMethod tags to every function/sub I wish to use inside the class?

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Can I use web service to host my classes?

    Yes, to every method you want accessible to the outside.

  8. #8

    Thread Starter
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Can I use web service to host my classes?

    Here's what I've got so far:
    [webservice]
    VB Code:
    1. <WebMethod()> _
    2.     Public Function GetBusException() As ExceptionBC
    3.         Dim exc As New ExceptionBC
    4.     End Function
    5.     <WebMethod()> _
    6.     Public Function GetDalExc() As ExceptionData
    7.         Return New ExceptionData
    8.     End Function
    [/webservice]
    [ReferencingProgram]
    VB Code:
    1. Dim clsws As wsLCL.Service1
    2.         Dim dalExc As wsLCL.ExceptionData = clsws.GetDalExc
    3.         Dim busExc As wsLCL.ExceptionBC = clsws.GetBusException
    [/ReferencingProgram]

    I can view all the public variables and properties, but non of the routines or functions. There are hundreds functions that I wish to access, so adding a web method tag would be a hassle. Is the a way to host an entire class object rather than just the objects inside it?

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Can I use web service to host my classes?

    Uhm... I'm not sure what you're trying to do, but if you want the class returned, you have to make its definition serializable. It'll be any generic method in your web service which returns this class. Does that make more sense now?

Posting Permissions

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



Click Here to Expand Forum to Full Width