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 Class to Web Service

passing Custom Class to Web Service

Scheduled Pinned Locked Moved Visual Basic
helpquestioncomtutorial
5 Posts 4 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 posted on here recently about this but I am still none the wiser so again I come seekign advice. I have a web service and a website consuming this service. I would like to pass a custom class from the website to the webservice and vice versa. The trouble is every time it gives me a error message saying "type is not the same as loclahost.Type" How can I get them to agree that it the same type? I have built a VERY basic example of what I am trying to which can be found here: WS passing cutom class.zip If anyone can help at all then I would be very appreciative.

    C D 2 Replies Last reply
    0
    • B BobsAfro

      I posted on here recently about this but I am still none the wiser so again I come seekign advice. I have a web service and a website consuming this service. I would like to pass a custom class from the website to the webservice and vice versa. The trouble is every time it gives me a error message saying "type is not the same as loclahost.Type" How can I get them to agree that it the same type? I have built a VERY basic example of what I am trying to which can be found here: WS passing cutom class.zip If anyone can help at all then I would be very appreciative.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Define the type in the web service. Use that type, as defined in the web service, in your code, don't create a new class of the same name.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      B 1 Reply Last reply
      0
      • C Christian Graus

        Define the type in the web service. Use that type, as defined in the web service, in your code, don't create a new class of the same name.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

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

        There is a large amount of work with the custom class before and after the web service call which would make it very hard to use the type webservicename.type Also I am trying to create a web services approach with my current apparoach as a back up which would make it very hard to use webservicename.type.

        D 1 Reply Last reply
        0
        • B BobsAfro

          There is a large amount of work with the custom class before and after the web service call which would make it very hard to use the type webservicename.type Also I am trying to create a web services approach with my current apparoach as a back up which would make it very hard to use webservicename.type.

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

          From the error it seems you defined the class in your code TWICE. You can't do that. You simply have no choice but to define it once and use that class in both your webserver and client projects. As it stands now, both of your applications are saying that they have the proper definition of the class, even though they are exactly the same code, they're not the same class.

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

          1 Reply Last reply
          0
          • B BobsAfro

            I posted on here recently about this but I am still none the wiser so again I come seekign advice. I have a web service and a website consuming this service. I would like to pass a custom class from the website to the webservice and vice versa. The trouble is every time it gives me a error message saying "type is not the same as loclahost.Type" How can I get them to agree that it the same type? I have built a VERY basic example of what I am trying to which can be found here: WS passing cutom class.zip If anyone can help at all then I would be very appreciative.

            D Offline
            D Offline
            Dave Herren
            wrote on last edited by
            #5

            After a very quick look at your example I believe you need: Dim Person As New localhost.Simple Dim Proxy As localhost.Service Person = Proxy.Returnnames(Person) instead of Dim Person As New Eurofins.Simple Dim Proxy As localhost.Service Person = Proxy.Returnnames(Person) My thought on this being that a proxy class of type 'Simple' should have been created when you made a reference to the webservice. These generated proxy classes are marked up with alot of Soap attributes that make everything work. If you are referencing another class with the name of Simple instead of the generated proxy class I can understand why you would get errors because localhost.Service is expecting a class within it's namespace. You can actually navigate to the proxy class code through the object browser if you double click on the web reference. Also it is possible to do this without a web reference and create your own proxy class (or the gerated one and modify it) if that is what you want or need. Here's a sample from my code using xml serialization, actual classes not included. private UserInformation GetUserInfoFromWebService(Uri ServiceUri) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ServiceUri); request.Method="GET"; request.Credentials = CredentialCache.DefaultCredentials; request.ContentType="application/x-www-form-urlencoded"; HttpWebResponse response = (HttpWebResponse) request.GetResponse(); XmlSerializer UserInfoSerializer= new XmlSerializer(typeof(UserInformation),"http://localhost/UserServices/"); Stream responseStream = response.GetResponseStream(); StreamReader responseReader = new StreamReader(responseStream); UserInformation UserInfo = (UserInformation)UserInfoSerializer.Deserialize(responseReader); responseStream.Close(); response.Close(); return UserInfo; } Hope this helps. -- modified at 11:12 Monday 21st May, 2007 -- modified at 11:14 Monday 21st May, 2007

            topcoderjax

            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