Using ORM entity in a web service

Thread is closed for posting
3 posts, 0 answers
  1. Bill
    Bill avatar
    42 posts
    Member since:
    Feb 2011

    Posted 11 Jun 2012 Link to this post

    Am I doing this correctly?

    I want to make an ORM entity available as a public property in my ebservice so when I consume the webservice, it will have knowledge of the business entity. I want to create a generic list of businesses and pass it to my WS

    I am using a web service to Push businesses from  website a TO b
    The Web service has a public property for the business entity

    Private _ Business As ORM.Business
       Public Property Business() As ORM.Business
               Return Me._Business
           End Get
           Set(value As ORM.Business)
               Me._Business = value
           End Set
       End Property

    I then want to create a list of businesses and  pass it to the following webservice method:
      <WebMethod()> _
        Public Function AddOrUpdateBusinesses(Businesses As List(Of ORM.Business)) As Boolean
    blah blah
        End Function

    Here is where I call the web service

      Dim ws As New BusinessWS
            Dim BusList As List(Of BusinessWS.Business) = Nothing'*********************************
    'Get data from DB A
            Using dbContext As New GMCC_Model
                Dim BusList As List(Of Business_Account) = (
                 From businessaccounts In dbContext.Business_Accounts
                 Where (businessaccounts.Status = "A" And businessaccounts.Allow3rdPartyAccess = 1)
                 Select businessaccounts).ToList
                If Not BusList Is Nothing Then
                    For Each bus As GMCC_ORM.Business_Account In BusList
    'create a new business to insert into DB B                   
              Dim Business As New ca.myWebsite.Business
                        Business.ActiveCity.City = bus.City
                        Business.ActiveCity.Country = "Canada"
                        Business.ActiveCity.Province = bus.Province
                        Business.BusinessActive = (bus.Status = "A")
                        Business.Address = bus.CivicAddress
                        Business.Email = bus.Email
                        Business.Name = bus.Name
                        Business.Postal = bus.Postal
                        Business.Telephone = bus.Telephone
                        Business.Website = bus.URL
                End If
            End Using

    The part around the ***** is where I am having trouble.
    Should I be able to do this?

    I may have some slight var naming problems because  I renamed anything that indicated the name of my website.

  2. Bill
    Bill avatar
    42 posts
    Member since:
    Feb 2011

    Posted 12 Jun 2012 Link to this post

    I found something that may shed some light...

    "Seeing the output of this web method highlights a question that is very important to many developers: what about interoperability? If you are creating web services that consuming applications written in various technologies will use (e.g., .NET, PHP, and Java), you do not want to return entity objects from your web services. Instead, you should use DTOs."

    That makes sense.
    It's OK to use ORM on my own server but on a 3d party server consuming my web service, I shouldn't complicate things by requiring them to understand and use ORM.
    I think I will create a simple entity class as a DTO containing the field values I need.
    "you most likely will want to create another, simpler class, as you did for ShortContact, and return that rather than the EntityObject. This type of class is referred to as a Data Transfer Object (DTO), also known as a value object. DTO is a well-known design pattern for transferring objects between applications. For this example, the EntityObject is perfectly fine, but it's still important to be aware of what you are sending through the pipe."

    If I understand DTO properly it is designed for that purpose- to allow passing simple entities between applications.I then simply need to read this on the web service and create the OTM insert/update for my database

  3. Viktor Zhivkov
    Viktor Zhivkov avatar
    324 posts

    Posted 14 Jun 2012 Link to this post

    Hello Bill,

    Going for a DTO layer in your services is a great step in the right direction. It will not only enable clients from different platforms to consume your services, but also will provide a level of abstraction that will hide many implementation details in you application and data layer.
    Add OpenAccess Service wizard can help you in the implementation phase by generating for you a complete service layer for you preferred service type. It will generate DTO classes, assemblers and repositories in addition to the bare-bone web service infrastructure required.
    If you have not tried it yet, give it a spin.

    In case you have any difficulties or need additional assistance do not hesitate to post in our forum.

    Kind regards,
    Viktor Zhivkov
    the Telerik team
    OpenAccess ORM Q2'12 Now Available! Get your hands on all the new stuff.
Back to Top