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. preserving same type information

preserving same type information

Scheduled Pinned Locked Moved C#
helpcsharpvisual-studioquestion
3 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.
  • A Offline
    A Offline
    avneeshb
    wrote on last edited by
    #1

    Hi! I am having an interesting problem while compiling code across different projects in the same VS.NET solution. Here is the scenario: 1. I have a project (called DataTypes) which defines common classes that I want to use throughout. 2. There is a webservice (WSA) which has a method which accepts two objects: MethodA(DataTypes.Type1 objType1, DataTypes.Type2 objType2) 3. This webservice also calls another webservice (WSB) from MethodA. The method in WSB has the following signature: MethodB(DataTypes.Type1 objType1, DataTypes.Type2 objType2). In the WSA project there is a web reference to WSB (lets call it refB). So this looks like: MethodA(DataTypes.Type1 objType1, DataTypes.Type2 objType2){ objType1.somefield=new_value; refB.MethodB(objType1, objType2); } When the client invokes WSA it passes the objects. MethodA modifies one of the parameters and passes these to WSB. 4. This code gives me a compilation error. The error message is "Cannot convert DataTypes.Type1 to refb.Type1". Understandably, the type information in the generated proxy for WSB refers to its interpretation of what Type1 is. Even though its the same as that in WSA. Any suggestions on how I can solve this problem? Thanks!

    S 1 Reply Last reply
    0
    • A avneeshb

      Hi! I am having an interesting problem while compiling code across different projects in the same VS.NET solution. Here is the scenario: 1. I have a project (called DataTypes) which defines common classes that I want to use throughout. 2. There is a webservice (WSA) which has a method which accepts two objects: MethodA(DataTypes.Type1 objType1, DataTypes.Type2 objType2) 3. This webservice also calls another webservice (WSB) from MethodA. The method in WSB has the following signature: MethodB(DataTypes.Type1 objType1, DataTypes.Type2 objType2). In the WSA project there is a web reference to WSB (lets call it refB). So this looks like: MethodA(DataTypes.Type1 objType1, DataTypes.Type2 objType2){ objType1.somefield=new_value; refB.MethodB(objType1, objType2); } When the client invokes WSA it passes the objects. MethodA modifies one of the parameters and passes these to WSB. 4. This code gives me a compilation error. The error message is "Cannot convert DataTypes.Type1 to refb.Type1". Understandably, the type information in the generated proxy for WSB refers to its interpretation of what Type1 is. Even though its the same as that in WSA. Any suggestions on how I can solve this problem? Thanks!

      S Offline
      S Offline
      Serge Lobko Lobanovsky
      wrote on last edited by
      #2

      Hi, I remember reading somewhere that when you pass an object to a webservice, it gets autoconverted to a proxy object, which _is not_ of the same type as the one being passed. That is the problem, imho. It is recommended to pass DTOs (data transfer objects) between layer boundaries (which is, when you call a method in a web service, you pass the layer boundary). Regards, Serge (Logic Software, Easy Projects .NET site)

      A 1 Reply Last reply
      0
      • S Serge Lobko Lobanovsky

        Hi, I remember reading somewhere that when you pass an object to a webservice, it gets autoconverted to a proxy object, which _is not_ of the same type as the one being passed. That is the problem, imho. It is recommended to pass DTOs (data transfer objects) between layer boundaries (which is, when you call a method in a web service, you pass the layer boundary). Regards, Serge (Logic Software, Easy Projects .NET site)

        A Offline
        A Offline
        avneeshb
        wrote on last edited by
        #3

        I guess one solution is to create the proxy using wsdl.exe. The generated proxy class contains the definitions of the Type1 and Type2 objects. If these are removed and the proxy is made to refer to WSAs types, then the example works.

        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