Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Passing custom object to web service

Passing custom object to web service

Scheduled Pinned Locked Moved Visual Basic
question
29 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B BobsAfro

    I am adding a web reference to it. I have removed it, recompiled the service and added it again and still has the same problem.

    B Offline
    B Offline
    BobsAfro
    wrote on last edited by
    #17

    Well I have managed to achieve what I want to but in a pretty crude way. I have written a function to serialize a class and one to deserialize it. Like this - Public Function Object2XML(ByVal obj As Object) As String Dim SW As New StringWriter Dim Ser As New XmlSerializer(obj.GetType()) Try Ser.Serialize(SW, obj) Return SW.ToString Catch ex As Exception Throw ex End Try End Function Public Function XML2OBject(ByVal xml As String, ByVal Type As Type) As Object Dim Obj As New Object Dim SR As New StringReader(xml) Dim Serializer As New System.Xml.Serialization.XmlSerializer(Type) Try Return Serializer.Deserialize(SR) Catch ex As Exception Throw ex End Try End Function But surely there is a better way to do it than this?

    1 Reply Last reply
    0
    • B BobsAfro

      I am adding a web reference to it. I have removed it, recompiled the service and added it again and still has the same problem.

      N Offline
      N Offline
      nlarson11
      wrote on last edited by
      #18

      if you want, you can email your solution and I can take a quick look (strip out any unnecessary code)

      B 1 Reply Last reply
      0
      • N nlarson11

        if you want, you can email your solution and I can take a quick look (strip out any unnecessary code)

        B Offline
        B Offline
        BobsAfro
        wrote on last edited by
        #19

        Thats a very kind offer but It is as very large project and I can't strip it easily. Don't think my boss would appreciate me sending you the whole of our site. Thanks anyway. Have you managed to pass a custom class to a web service before successfully?

        N 1 Reply Last reply
        0
        • B BobsAfro

          Thats a very kind offer but It is as very large project and I can't strip it easily. Don't think my boss would appreciate me sending you the whole of our site. Thanks anyway. Have you managed to pass a custom class to a web service before successfully?

          N Offline
          N Offline
          nlarson11
          wrote on last edited by
          #20

          yes we do it all the time. we do not however use web references (not that I think that's the problem). we go after the webservice dynamically...

          B 1 Reply Last reply
          0
          • N nlarson11

            yes we do it all the time. we do not however use web references (not that I think that's the problem). we go after the webservice dynamically...

            B Offline
            B Offline
            BobsAfro
            wrote on last edited by
            #21

            How do you go after the webservice dynamically as you put it?

            N 2 Replies Last reply
            0
            • B BobsAfro

              How do you go after the webservice dynamically as you put it?

              N Offline
              N Offline
              nlarson11
              wrote on last edited by
              #22

              let me put a quick sample together...

              1 Reply Last reply
              0
              • B BobsAfro

                How do you go after the webservice dynamically as you put it?

                N Offline
                N Offline
                nlarson11
                wrote on last edited by
                #23

                example: include system.web.services in your exe project make the webservice (if not already) a virtual directory the line - Me.Url = "http://localhost/cpwebproj/PopulateMyObj.asmx" allows you to change localhost to any ip/dns name hope this helps... ********this goes in your dll*********** _ Public Class MyObj Public sName As String Public sAddr As String Public sCity As String Public sState As String Public sZip As String End Class ********this goes in your exe*********** Public Class Form1 Inherits System.Windows.Forms.Form Private Sub Form1_Load1(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim oEntity As New CPDllProj.MyObj Dim oTrans As New Trans oEntity = oTrans.Request(oEntity) MsgBox(oEntity.sName) MsgBox(oEntity.sAddr) MsgBox(oEntity.sCity) MsgBox(oEntity.sState) MsgBox(oEntity.sZip) End End Sub end class Imports System.Web.Services Imports System.Web.Services.Protocols _ Public Class Trans Inherits System.Web.Services.Protocols.SoapHttpClientProtocol _ Public Function Request(ByVal oEntity As CPDllProj.MyObj) As CPDllProj.MyObj Dim oa() As Object Me.Url = "http://localhost/cpwebproj/PopulateMyObj.asmx" Me.Timeout = 60000 oa = Me.Invoke("Request", New Object() {oEntity}) Return CType(oa(0), CPDllProj.MyObj) End Function End Class ********this goes in your webservice*********** Imports System.Web.Services _ Public Class PopulateMyObj Inherits System.Web.Services.WebService #Region " Web Services Designer Generated Code " Public Sub New() MyBase.New() 'This call is required by the Web Services Designer. InitializeComponent() 'Add you

                B 1 Reply Last reply
                0
                • N nlarson11

                  example: include system.web.services in your exe project make the webservice (if not already) a virtual directory the line - Me.Url = "http://localhost/cpwebproj/PopulateMyObj.asmx" allows you to change localhost to any ip/dns name hope this helps... ********this goes in your dll*********** _ Public Class MyObj Public sName As String Public sAddr As String Public sCity As String Public sState As String Public sZip As String End Class ********this goes in your exe*********** Public Class Form1 Inherits System.Windows.Forms.Form Private Sub Form1_Load1(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim oEntity As New CPDllProj.MyObj Dim oTrans As New Trans oEntity = oTrans.Request(oEntity) MsgBox(oEntity.sName) MsgBox(oEntity.sAddr) MsgBox(oEntity.sCity) MsgBox(oEntity.sState) MsgBox(oEntity.sZip) End End Sub end class Imports System.Web.Services Imports System.Web.Services.Protocols _ Public Class Trans Inherits System.Web.Services.Protocols.SoapHttpClientProtocol _ Public Function Request(ByVal oEntity As CPDllProj.MyObj) As CPDllProj.MyObj Dim oa() As Object Me.Url = "http://localhost/cpwebproj/PopulateMyObj.asmx" Me.Timeout = 60000 oa = Me.Invoke("Request", New Object() {oEntity}) Return CType(oa(0), CPDllProj.MyObj) End Function End Class ********this goes in your webservice*********** Imports System.Web.Services _ Public Class PopulateMyObj Inherits System.Web.Services.WebService #Region " Web Services Designer Generated Code " Public Sub New() MyBase.New() 'This call is required by the Web Services Designer. InitializeComponent() 'Add you

                  B Offline
                  B Offline
                  BobsAfro
                  wrote on last edited by
                  #24

                  Thanks very much for your help. But i'm afraid you've got a bit beyond me there.

                  N 1 Reply Last reply
                  0
                  • B BobsAfro

                    Thanks very much for your help. But i'm afraid you've got a bit beyond me there.

                    N Offline
                    N Offline
                    nlarson11
                    wrote on last edited by
                    #25

                    maybe, maybe not... do this and I'll show you how I got the code I sent: +add a webrefence to your asmx page. +right-click on the new reference and left-click on view in object browser +expand the plus +right-click on your class name +left-click on goto definition if you look the upper part of the code, its your routine name showing it's pointing to localhost. this is the code I sent you...

                    B 1 Reply Last reply
                    0
                    • N nlarson11

                      maybe, maybe not... do this and I'll show you how I got the code I sent: +add a webrefence to your asmx page. +right-click on the new reference and left-click on view in object browser +expand the plus +right-click on your class name +left-click on goto definition if you look the upper part of the code, its your routine name showing it's pointing to localhost. this is the code I sent you...

                      B Offline
                      B Offline
                      BobsAfro
                      wrote on last edited by
                      #26

                      "+add a webrefence to your asmx page." You mean add a webreference to my web service? In which case a reference to what? If you meant add a web reference to my consuming project I have and tried clicking view in browser but it was greyed out.

                      B N 2 Replies Last reply
                      0
                      • B BobsAfro

                        "+add a webrefence to your asmx page." You mean add a webreference to my web service? In which case a reference to what? If you meant add a web reference to my consuming project I have and tried clicking view in browser but it was greyed out.

                        B Offline
                        B Offline
                        BobsAfro
                        wrote on last edited by
                        #27

                        For some reason view in browser is no longer gereyed out (no idea what I've done). but there is no option to view in object browser.

                        1 Reply Last reply
                        0
                        • B BobsAfro

                          "+add a webrefence to your asmx page." You mean add a webreference to my web service? In which case a reference to what? If you meant add a web reference to my consuming project I have and tried clicking view in browser but it was greyed out.

                          N Offline
                          N Offline
                          nlarson11
                          wrote on last edited by
                          #28

                          in your exe, rightclick on the references and choose add web reference yes point to your web service using my example is would look like http://localhost/cpwebproj/populatemyobj.asmx not view in browser, view in 'object browser'

                          B 1 Reply Last reply
                          0
                          • N nlarson11

                            in your exe, rightclick on the references and choose add web reference yes point to your web service using my example is would look like http://localhost/cpwebproj/populatemyobj.asmx not view in browser, view in 'object browser'

                            B Offline
                            B Offline
                            BobsAfro
                            wrote on last edited by
                            #29

                            The webreference appears as a folder with 3 files inside none of which have an option to view in object browser on right click.

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups