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 Offline
    B Offline
    BobsAfro
    wrote on last edited by
    #1

    I have a custom object which is is a simple model with only a few strings and booleans as fields. I would like to pass this to a web service. Is there anyway to do this? I currently have the class in both projects but it says "CustomClass is not of type web_service_name.CustomClass" when I try to pass it in the consuming project. How can i tell it they are the same class?

    N 1 Reply Last reply
    0
    • B BobsAfro

      I have a custom object which is is a simple model with only a few strings and booleans as fields. I would like to pass this to a web service. Is there anyway to do this? I currently have the class in both projects but it says "CustomClass is not of type web_service_name.CustomClass" when I try to pass it in the consuming project. How can i tell it they are the same class?

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

      You can only use 1 definition of the class. Both the UI and the WebService needs to reference a dll that has the definition of the class. It needs to also be serializable because it will be converted to xml for the transaction _ Public Class Hello public sName as string . . . End class

      B 1 Reply Last reply
      0
      • N nlarson11

        You can only use 1 definition of the class. Both the UI and the WebService needs to reference a dll that has the definition of the class. It needs to also be serializable because it will be converted to xml for the transaction _ Public Class Hello public sName as string . . . End class

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

        Thanks but that has nothing to do with my problem. They are both the same definition. What I am trying to do is to get it to recognise that.

        N 1 Reply Last reply
        0
        • B BobsAfro

          Thanks but that has nothing to do with my problem. They are both the same definition. What I am trying to do is to get it to recognise that.

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

          You said, that you have the class in both projects. Does both mean you have the class defined in each or referenced in each? Defined will not work, it must be referenced in each....

          N 1 Reply Last reply
          0
          • N nlarson11

            You said, that you have the class in both projects. Does both mean you have the class defined in each or referenced in each? Defined will not work, it must be referenced in each....

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

            for further clarification... it compares the object using the full assembly name if your ui project is codeproject and your class is hello codeproject.hello - is the full class name if your webservice is webproject and your class is hello webproject.hello - is the full class name does codeproject.hello = webproject.hello ? you think it does but the full assembly names do no match so it thinks they are different objects...

            B 1 Reply Last reply
            0
            • N nlarson11

              for further clarification... it compares the object using the full assembly name if your ui project is codeproject and your class is hello codeproject.hello - is the full class name if your webservice is webproject and your class is hello webproject.hello - is the full class name does codeproject.hello = webproject.hello ? you think it does but the full assembly names do no match so it thinks they are different objects...

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

              Exactly!!! How can I get these to be the same? Surely it shouldn't be too difficult to just send an object with only a couple of string in it!

              N 1 Reply Last reply
              0
              • B BobsAfro

                Exactly!!! How can I get these to be the same? Surely it shouldn't be too difficult to just send an object with only a couple of string in it!

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

                that's what I'm talking about with referencing a dll... create a dll (let's call it A) put the definition of the class Hello in A in your exe reference A use A.Hello everywhere in your code in you webservice reference A use A.Hello everywhere in your code because the full assembly name is A.hello...when you pass A.hello to your webservice it will see that A.Hello = A.Hello and accept the object as being the same... -

                B 1 Reply Last reply
                0
                • N nlarson11

                  that's what I'm talking about with referencing a dll... create a dll (let's call it A) put the definition of the class Hello in A in your exe reference A use A.Hello everywhere in your code in you webservice reference A use A.Hello everywhere in your code because the full assembly name is A.hello...when you pass A.hello to your webservice it will see that A.Hello = A.Hello and accept the object as being the same... -

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

                  Thanks for you help so far. I have compiled the class into a dll and placed it into the bin directory. Now what do I do with it?

                  N B 2 Replies Last reply
                  0
                  • B BobsAfro

                    Thanks for you help so far. I have compiled the class into a dll and placed it into the bin directory. Now what do I do with it?

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

                    i'll assume your exe and your webservice are in the same solution add the dll project to the solution in your exe project, do an add reference and point to the dll project - don't move the dll to the bin when you compile the dll will come along automatically when you compile in your webservice project, do an add reference and point to the dll project - don't move the dll to the bin when you compile the dll will come along automatically when you compile

                    1 Reply Last reply
                    0
                    • B BobsAfro

                      Thanks for you help so far. I have compiled the class into a dll and placed it into the bin directory. Now what do I do with it?

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

                      Okay I have imported it into both projects so they are both using the dll. But it still says "namespace.classname can not be converted to web_service_name.classname" Same problem as before.

                      D N 2 Replies Last reply
                      0
                      • B BobsAfro

                        Okay I have imported it into both projects so they are both using the dll. But it still says "namespace.classname can not be converted to web_service_name.classname" Same problem as before.

                        D Offline
                        D Offline
                        Dave Kreskowiak
                        wrote on last edited by
                        #11

                        Did you remove the old class definitions from your code?

                        A guide to posting questions on CodeProject[^]
                        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                             2006, 2007

                        B 1 Reply Last reply
                        0
                        • B BobsAfro

                          Okay I have imported it into both projects so they are both using the dll. But it still says "namespace.classname can not be converted to web_service_name.classname" Same problem as before.

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

                          are you using web reference or going after the webservice dynamically? if web reference -- try to remove the reference and re-add it...

                          B 1 Reply Last reply
                          0
                          • D Dave Kreskowiak

                            Did you remove the old class definitions from your code?

                            A guide to posting questions on CodeProject[^]
                            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                                 2006, 2007

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

                            I have removed the old class.

                            B 1 Reply Last reply
                            0
                            • B BobsAfro

                              I have removed the old class.

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

                              Removed the reference and added it again and still no luck.

                              N 1 Reply Last reply
                              0
                              • B BobsAfro

                                Removed the reference and added it again and still no luck.

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

                                before you re-addedit, did you first compile the webservice with the new class?

                                1 Reply Last reply
                                0
                                • N nlarson11

                                  are you using web reference or going after the webservice dynamically? if web reference -- try to remove the reference and re-add it...

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

                                  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 N 2 Replies 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.

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