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. C#
  4. passing objects via WebServices

passing objects via WebServices

Scheduled Pinned Locked Moved C#
csharpc++javasysadminhelp
6 Posts 2 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.
  • R Offline
    R Offline
    Raphael Amorim
    wrote on last edited by
    #1

    Hello all, I got this object obj, it's an instance of CTestClass. Now I want to pass this object across my network using MyWebService. So, I've wrote a Method called GoObject: [WebMethod] [XmlInclude(typeof(CTestClass))] public bool GoObject(object obj) { if(obj is CTestClass) { return true; } return false; } But, whenever I call this method passing a client side instance of CTestClass, I get the following error message: The type TesteClass.CTestClass was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically. What's the professional way to perform what I'm trying to :) Best Regards Raphael Amorim Dantas Leite VC++, Java and C# programmer. Win32 and PocketPC enviroments

    H 1 Reply Last reply
    0
    • R Raphael Amorim

      Hello all, I got this object obj, it's an instance of CTestClass. Now I want to pass this object across my network using MyWebService. So, I've wrote a Method called GoObject: [WebMethod] [XmlInclude(typeof(CTestClass))] public bool GoObject(object obj) { if(obj is CTestClass) { return true; } return false; } But, whenever I call this method passing a client side instance of CTestClass, I get the following error message: The type TesteClass.CTestClass was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically. What's the professional way to perform what I'm trying to :) Best Regards Raphael Amorim Dantas Leite VC++, Java and C# programmer. Win32 and PocketPC enviroments

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      As the error states, the WSDL for Web Service is missing a type declaration for the CTestClass. You either need to edit the WSDL manually, or better yet - do what the error tells you. Include the CTestClass type using either the XmlIncludeAttribute (better portability) or the SoapIncludeAttribute that take a Type as a parameter:

      public class Test : WebService
      {
      [WebMethod]
      [XmlInclude(typeof(CTestClass))]
      public bool GenericUpdate(object o) { /* ... */ }
      }

      Otherwise, the web service doesn't understand know the WSDL for the CTestClass type and can't deserialize it. See the .NET Framework documentation for XmlIncludeAttribute for a good example. PS: You shouldn't use the old Polish notation with classes and members in .NET, like beginning classes with a "C". Most languages have language guidelines that developers should follow when possible to make all libraries consistent and easy to use. There is a design guidelines in the .NET Framework that describes the changes (really not that bad and mostly for public/protected members), but they are good to follow.

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      R 1 Reply Last reply
      0
      • H Heath Stewart

        As the error states, the WSDL for Web Service is missing a type declaration for the CTestClass. You either need to edit the WSDL manually, or better yet - do what the error tells you. Include the CTestClass type using either the XmlIncludeAttribute (better portability) or the SoapIncludeAttribute that take a Type as a parameter:

        public class Test : WebService
        {
        [WebMethod]
        [XmlInclude(typeof(CTestClass))]
        public bool GenericUpdate(object o) { /* ... */ }
        }

        Otherwise, the web service doesn't understand know the WSDL for the CTestClass type and can't deserialize it. See the .NET Framework documentation for XmlIncludeAttribute for a good example. PS: You shouldn't use the old Polish notation with classes and members in .NET, like beginning classes with a "C". Most languages have language guidelines that developers should follow when possible to make all libraries consistent and easy to use. There is a design guidelines in the .NET Framework that describes the changes (really not that bad and mostly for public/protected members), but they are good to follow.

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        R Offline
        R Offline
        Raphael Amorim
        wrote on last edited by
        #3

        How do I edit the WSDL manually? Raphael Amorim Dantas Leite VC++, Java and C# programmer. Win32 and PocketPC enviroments

        H 1 Reply Last reply
        0
        • R Raphael Amorim

          How do I edit the WSDL manually? Raphael Amorim Dantas Leite VC++, Java and C# programmer. Win32 and PocketPC enviroments

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          Short answer...don't! There's a lot of work involved (and you really have to understand WSDL) and ever time you compile with changes you'd either invalidate the WSDL or loose it. All you'd be doing, though, is adding a definition for the CTestClass, which is what using the simple one-liner XmlIncludeAttribute above the method would do. I strongly suggest using the latter route. If, for some reason, you need to edit the WSDL directly I suggest you check-out some of the MSDN articles on Web Services. Several of them do this but they have enterprise-ready solutions that sometimes require more than the framework provides. From what I can tell, the XmlIncludeAttribute is exactly what you need (since ASP.NET will pull the type from the dependent assembly which must be there for the o is CTestClass statement to work anyway, into the WSDL generated for WS clients).

          -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

          R 1 Reply Last reply
          0
          • H Heath Stewart

            Short answer...don't! There's a lot of work involved (and you really have to understand WSDL) and ever time you compile with changes you'd either invalidate the WSDL or loose it. All you'd be doing, though, is adding a definition for the CTestClass, which is what using the simple one-liner XmlIncludeAttribute above the method would do. I strongly suggest using the latter route. If, for some reason, you need to edit the WSDL directly I suggest you check-out some of the MSDN articles on Web Services. Several of them do this but they have enterprise-ready solutions that sometimes require more than the framework provides. From what I can tell, the XmlIncludeAttribute is exactly what you need (since ASP.NET will pull the type from the dependent assembly which must be there for the o is CTestClass statement to work anyway, into the WSDL generated for WS clients).

            -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

            R Offline
            R Offline
            Raphael Amorim
            wrote on last edited by
            #5

            So, Is something like this? [WebMethod] [XmlInclude(typeof(CTestClass))] [XmlIncludeAttribute(typeof(CTestClass))] public bool GoObject(object obj) { if(obj is CTestClass) { return true; } return true; } Raphael Amorim Dantas Leite VC++, Java and C# programmer. Win32 and PocketPC enviroments

            H 1 Reply Last reply
            0
            • R Raphael Amorim

              So, Is something like this? [WebMethod] [XmlInclude(typeof(CTestClass))] [XmlIncludeAttribute(typeof(CTestClass))] public bool GoObject(object obj) { if(obj is CTestClass) { return true; } return true; } Raphael Amorim Dantas Leite VC++, Java and C# programmer. Win32 and PocketPC enviroments

              H Offline
              H Offline
              Heath Stewart
              wrote on last edited by
              #6

              You actually have the XmlIncludeAttribute specified twice! Remember that languages like C#, VB.NET, and MC++ don't require the "Attribute" suffix, though some languages might (it depends on the compiler). Simply:

              [WebMethod]
              [XmlInclude(typeof(CTestClass))]
              public bool GetObject(object obj)
              {
              if (obj is CTestClass) return true;
              return true;
              }

              And make sure that the assembly in which CTestClass is defined is referenced as a dependent assembly (or in the Web Service assembly itself, although this doesn't make any sense since the client can't use the type (even if retyped, since a Type is defined by its namespace, class name, assembly name, and public key token).

              -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

              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