Problem with Nusoap & c#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • BOB Le Bricoleur

    Problem with Nusoap & c#

    Hi,

    I have a small web service written in PHP with NuSOAP which describes a
    type "Categorie" and a function "GetCategories( )".

    I'm trying to access it with a C# application.

    Here is the generated code where the error occurs:
    -------------------------------------------------------------------
    public Categorie[] GetCategories() {
    object[] results = this.Invoke("Ge tCategories", new object[0]); //OK
    return ((Categorie[])(results[0])); //ERR
    }
    -------------------------------------------------------------------


    I get an error at runtime:
    "System.Invalid CastException", can't cast an object of type "Categorie"
    to an object of type "Categorie" !!

    The invoke method works fine, all the data is in the results array.

    Thanks for your help.


  • Daniel Cigic

    #2
    Re: Problem with Nusoap & c#

    Hi Bob,

    For the cast to succeed both array must have the same number of dimensions
    ant there must be an implicit or explicit conversion from the source element
    type to the target element type.
    You could use just one of the overloaded Array.Copy() methods. Looking at
    you code I see
    "return ((Categorie[])(results[0]));". Are you sure that you have array of
    Categorie in first array - result[0] element?


    Daniel

    "BOB Le Bricoleur" <bob@bob.bobwro te in message
    news:mn.d3917d8 2e3eaacca.86280 @bob.bob...
    Hi,
    >
    I have a small web service written in PHP with NuSOAP which describes a
    type "Categorie" and a function "GetCategories( )".
    >
    I'm trying to access it with a C# application.
    >
    Here is the generated code where the error occurs:
    -------------------------------------------------------------------
    public Categorie[] GetCategories() {
    object[] results = this.Invoke("Ge tCategories", new object[0]); //OK
    return ((Categorie[])(results[0])); //ERR
    }
    -------------------------------------------------------------------
    >
    >
    I get an error at runtime:
    "System.Invalid CastException", can't cast an object of type "Categorie" to
    an object of type "Categorie" !!
    >
    The invoke method works fine, all the data is in the results array.
    >
    Thanks for your help.
    >
    >

    Comment

    • BOB Le Bricoleur

      #3
      Re: Problem with Nusoap &amp; c#

      Daniel Cigic a exposé le 26/02/2008 :
      Hi Bob,
      >
      For the cast to succeed both array must have the same number of dimensions
      ant there must be an implicit or explicit conversion from the source element
      type to the target element type.
      You could use just one of the overloaded Array.Copy() methods. Looking at you
      code I see
      I get the same error messages with Array.Copy()

      "return ((Categorie[])(results[0]));". Are you sure that you have array of
      Categorie in first array - result[0] element?
      I am pretty sure; here is what the debugger gives for "results[0]":

      results[0]:{Dimensions:[3]}
      [0]:{ModuleAstuces .localhost.Cate gorie}
      [1]:{ModuleAstuces .localhost.Cate gorie}
      [2]:{ModuleAstuces .localhost.Cate gorie}


      The code was generated by visual studio 2005, it should work without
      modifying it. This is weird..


      Comment

      Working...