WebServices and Class Files

Last post 10-18-2007 3:03 AM by Samu Zhang - MSFT. 11 replies.

Sort Posts:

  • WebServices and Class Files

    10-15-2007, 9:25 AM
    • Participant
      871 point Participant
    • GavDraper
    • Member since 07-11-2006, 3:15 PM
    • England
    • Posts 176

    I'm trying to expose an API for a web application, through web services. I've never really used web services before and have a couple of quieres.

     I created a new web service project and a method in that project  to test I could run the method and get a response and that worked fine. However I want to create about 10 different class files inside this web service to expose different functionality and this is where I'm having problems. It seems any methods I put inside the default class in the asmx file that I mark as <webMethod()> can be run fine, however I'm unable to see or use any of the classes I have created outside of the Asmx file. This is going to be a fairly big project so I want to split the classes up can anyone tell me the best way to do this?

     

    Thanks for any help

    Please Remember to click "Mark as Answer" on this post if it helped you.
    -------------------
    http://www.crazycoder.co.uk
    G
  • Re: WebServices and Class Files

    10-15-2007, 11:45 AM
    • Member
      350 point Member
    • aaron.croft
    • Member since 02-21-2007, 11:47 PM
    • Posts 76

    Web service technologies merely expose an "interface."  It is up to you what you want to do internal to that project with multiple classes, etc., but anything exposed outside of the web service project must be in a class asociated with an .asmx and marked as a WebMethod.  From within this web method you can use those classes, but they won't be exposed to consumers of the web service.

    It sounds like what you really want is multiple services; just add multiple .asmx services and you will create muiltiple "classes", one for each service.  A web service project can contain as many web services as you desire.     

  • Re: WebServices and Class Files

    10-15-2007, 11:49 AM
    • Participant
      871 point Participant
    • GavDraper
    • Member since 07-11-2006, 3:15 PM
    • England
    • Posts 176

    I was really hopping there would be a way to have 1 asmx file and lots of VB class files. so from what I understand I need an asmx file for each class? so if I wanted 30 classes does that mean the developer who wants to access these classes would need to reference 30 different asmx addresses?

     

    Thanks

    Please Remember to click "Mark as Answer" on this post if it helped you.
    -------------------
    http://www.crazycoder.co.uk
    G
  • Re: WebServices and Class Files

    10-15-2007, 11:57 AM
    • Member
      350 point Member
    • aaron.croft
    • Member since 02-21-2007, 11:47 PM
    • Posts 76

    Pretty much.

     You could certainly have 1 .asmx, and 30 classes.  The .asmx is the only class that actually has exposable WebMethods though, and then it could call into the various 30 classes that had the actual logic.


    For instance:

     

    MyService.asmx

    MyService.asmx.vb

    <WebMethod()>_

    Public Function GetCustomerData() as DataSet

        Return CustomerClass.GetData() 

    End Function 

     

    <WebMethod()>_

    Public Function GetEmployeeData() as DataSet

     Return EmployeeClass.GetData()

    End Function 

     

    Then the web service project could have a CustomerClass and an EmployeeClass with the corresponding logic and methods.  The Customer and Employee classes could be private classes that aren't seen outside the project, and only the single .asmx with it's corresponding methods is referenced. 

  • Re: WebServices and Class Files

    10-15-2007, 12:09 PM
    • Participant
      871 point Participant
    • GavDraper
    • Member since 07-11-2006, 3:15 PM
    • England
    • Posts 176

    I'm not planning on working with Datasets I really want to work with my classes e.g

     

    Client side

    ------------------------------

    dim cust as new Customer()
    cust.FindCustomer("CompanyName")
    cust.CompanyName "NewCompanyName"
    cust.save
    dim usr as new CustomerUser = cust.FindUser("Surname")
    usr.Surname = "new Surname"
    usr.Save()
    
    

    Where both customer and CustomerUser are differnet classes in my web service project. Is this possible?

    Please Remember to click "Mark as Answer" on this post if it helped you.
    -------------------
    http://www.crazycoder.co.uk
    G
  • Re: WebServices and Class Files

    10-15-2007, 1:58 PM
    • Member
      350 point Member
    • aaron.croft
    • Member since 02-21-2007, 11:47 PM
    • Posts 76

    Not really.

     A Web service is just a class with methods that can return data.  That's it.

    You can't return objects with any other methods (sort of can with DataSets but that's just a .Net trick). The "objects" returned are merely containers of data.

     So your code sample doesn't really work with web services exactly.  Web Services do not provide "Object Oriented" API's. 

  • Re: WebServices and Class Files

    10-16-2007, 11:52 AM
    • Participant
      871 point Participant
    • GavDraper
    • Member since 07-11-2006, 3:15 PM
    • England
    • Posts 176

    Microsoft CRM exposes some of its SDK through web services and allows me to create classes from that service all with intellisence. For example

      

    Dim service As CrmSdk.CrmService = New CrmSdk.CrmService()
    Dim oppertunity As New CrmSdk.opportunity()

     

    Where both Oppertunity and CrmService are classes contained in the web service, I have no DLL's installed locally for this SDK.

    Any idea how they have done this?

    Please Remember to click "Mark as Answer" on this post if it helped you.
    -------------------
    http://www.crazycoder.co.uk
    G
  • Re: WebServices and Class Files

    10-16-2007, 4:51 PM
    • Member
      350 point Member
    • aaron.croft
    • Member since 02-21-2007, 11:47 PM
    • Posts 76

     Yes, as mentioned that is done with multiple.asmx web references.

    Those are proxy classes.  But they are not "OOP" based classes.. they don't have feilds and properties and you don't pass them around.


    They are more like utility classes or modules exposed on the client for calling the methods of the web service.. and the objects the web service returns do not have complicated methods or OOP functionality, they are merly data structures.

  • Re: WebServices and Class Files

    10-17-2007, 3:35 AM
    • Participant
      871 point Participant
    • GavDraper
    • Member since 07-11-2006, 3:15 PM
    • England
    • Posts 176

    Sorry to keep dragging this on but one last question, for the CRM service I mentioned above I only referenced 1 asmx file in my project and I had access to all the different classes from that one file. How would I achieve this?

     Also is there any good books or sites for learning this all the web service information I find is just basic hello world stuff, I want to know how to create these type of proxy classes thank you for all your hlp so far.

    Please Remember to click "Mark as Answer" on this post if it helped you.
    -------------------
    http://www.crazycoder.co.uk
    G
  • Re: WebServices and Class Files

    10-17-2007, 1:40 PM
    • Member
      30 point Member
    • bubbha70
    • Member since 09-14-2007, 8:02 PM
    • Posts 17

    Create a class library and reference the DLL from your webservice.

    Or place the class code into your webservice project and use them.

     Kind Regards,

    Bubbha70

  • Re: WebServices and Class Files

    10-17-2007, 4:22 PM
    Answer
    • Member
      350 point Member
    • aaron.croft
    • Member since 02-21-2007, 11:47 PM
    • Posts 76

     Any classes that are either return types or input parameters of your web methods will also be a part of what get's created in the client upon making a web reference.  They don't need to be in a class library.

     As I said though, these "classes" can't have methods, only properties and fields.

  • Re: WebServices and Class Files

    10-18-2007, 3:03 AM

    Hi GavDraper,

    You can expose methods marked as <webmethod> and invoke these classes you created outside of the asmx file.

    The default class in the asmx file is just like a proxy which expose web methods to client application. In a word, one interface many business classes.

    Here are some resources below

    http://quickstarts.asp.net/QuickStartv20/webservices/doc/BPConformance.aspx   

    __________________________________________________

    Sincerely,
    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.


    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
Page 1 of 1 (12 items)