Help! Web service can't be accessed!

Discussion in 'ASP .Net Web Services' started by James, Mar 1, 2005.

  1. James

    James Guest

    I encountered a problem caused by calling a web method and returning a
    derived class one of whose property overrides its base property.

    Definitions of the two classes are as follows:
    public class Class1
    {
    public Class1()
    {
    }

    public string Name;
    }

    public class Class2 : Class1
    {
    public Class2()
    {
    }

    public new string[] Name;
    }

    the web method is as follows:
    [WebMethod]
    public Class2 Test()
    {
    return new Class2();
    }

    I can compile it correctly, however, an exception was thrown when referring
    the web service:

    Member Class2.Name of type System.String[] hides base class member
    Class1.Name of type System.String. Use XmlElementAttribute or
    XmlAttributeAttribute to specify a new name.

    I don't know how to use XmlAttributeAttribute or
    XmlElementAttributeAttribute class to solve the problem, but I tried the
    following style and failed:

    [XmlElement("Class2Name", typeof(string[])),
    XmlElement("Class1Name", typeof(string))]
    public new string[] Name;

    Any ideas will be greatly appreciately and thanks in advance.
     
    James, Mar 1, 2005
    #1
    1. Advertising

  2. How about:


    XmlElement[DataType="string[]", ElementName="Class2Name"]

    or

    XmlAttribute [DataType="string[]", AttributeName="Class2Name"]

    (I think you have the DataType and ElementName reversed in your code)

    Hope that helps.

    --
    Manohar Kamath
    Editor, .netWire
    www.dotnetwire.com


    "James" <> wrote in message
    news:...
    > I encountered a problem caused by calling a web method and returning a
    > derived class one of whose property overrides its base property.
    >
    > Definitions of the two classes are as follows:
    > public class Class1
    > {
    > public Class1()
    > {
    > }
    >
    > public string Name;
    > }
    >
    > public class Class2 : Class1
    > {
    > public Class2()
    > {
    > }
    >
    > public new string[] Name;
    > }
    >
    > the web method is as follows:
    > [WebMethod]
    > public Class2 Test()
    > {
    > return new Class2();
    > }
    >
    > I can compile it correctly, however, an exception was thrown when

    referring
    > the web service:
    >
    > Member Class2.Name of type System.String[] hides base class member
    > Class1.Name of type System.String. Use XmlElementAttribute or
    > XmlAttributeAttribute to specify a new name.
    >
    > I don't know how to use XmlAttributeAttribute or
    > XmlElementAttributeAttribute class to solve the problem, but I tried the
    > following style and failed:
    >
    > [XmlElement("Class2Name", typeof(string[])),
    > XmlElement("Class1Name", typeof(string))]
    > public new string[] Name;
    >
    > Any ideas will be greatly appreciately and thanks in advance.
     
    Manohar Kamath, Mar 1, 2005
    #2
    1. Advertising

  3. James

    James Guest

    Thanks for your kindly reply Manohar.

    Unfortunetely it didn't work. I wrote in that way 'cause there is a
    constructor of the XmlElementAttribute class accepting the ElementName and
    Type parameters in the exactly sequence as I wrote.

    Any other suggestions?

    Thanks again.

    "Manohar Kamath" wrote:

    > How about:
    >
    >
    > XmlElement[DataType="string[]", ElementName="Class2Name"]
    >
    > or
    >
    > XmlAttribute [DataType="string[]", AttributeName="Class2Name"]
    >
    > (I think you have the DataType and ElementName reversed in your code)
    >
    > Hope that helps.
    >
    > --
    > Manohar Kamath
    > Editor, .netWire
    > www.dotnetwire.com
    >
    >
    > "James" <> wrote in message
    > news:...
    > > I encountered a problem caused by calling a web method and returning a
    > > derived class one of whose property overrides its base property.
    > >
    > > Definitions of the two classes are as follows:
    > > public class Class1
    > > {
    > > public Class1()
    > > {
    > > }
    > >
    > > public string Name;
    > > }
    > >
    > > public class Class2 : Class1
    > > {
    > > public Class2()
    > > {
    > > }
    > >
    > > public new string[] Name;
    > > }
    > >
    > > the web method is as follows:
    > > [WebMethod]
    > > public Class2 Test()
    > > {
    > > return new Class2();
    > > }
    > >
    > > I can compile it correctly, however, an exception was thrown when

    > referring
    > > the web service:
    > >
    > > Member Class2.Name of type System.String[] hides base class member
    > > Class1.Name of type System.String. Use XmlElementAttribute or
    > > XmlAttributeAttribute to specify a new name.
    > >
    > > I don't know how to use XmlAttributeAttribute or
    > > XmlElementAttributeAttribute class to solve the problem, but I tried the
    > > following style and failed:
    > >
    > > [XmlElement("Class2Name", typeof(string[])),
    > > XmlElement("Class1Name", typeof(string))]
    > > public new string[] Name;
    > >
    > > Any ideas will be greatly appreciately and thanks in advance.

    >
    >
    >
     
    James, Mar 4, 2005
    #3
  4. James

    Dan Rogers Guest

    Try not to design classes like this. What are you trying to accomplish?
    Have two fields with one accessor? Or have one override the definition of
    the other? Or is this just a mistake on your part?

    Try to put a specific XmlElementAttribute on each name property - don't
    just change the one. Do both, to remove the ambiguity.
    --------------------
    >Thread-Topic: Help! Web service can't be accessed!
    >thread-index: AcUeCldcUf2nKCTvSqimQaJMt0hT/A==
    >X-WBNR-Posting-Host: 61.149.242.79
    >From: "=?Utf-8?B?SmFtZXM=?=" <>
    >Subject: Help! Web service can't be accessed!
    >Date: Mon, 28 Feb 2005 18:57:01 -0800
    >Lines: 45
    >Message-ID: <>
    >MIME-Version: 1.0
    >Content-Type: text/plain;
    > charset="Utf-8"
    >Content-Transfer-Encoding: 7bit
    >X-Newsreader: Microsoft CDO for Windows 2000
    >Content-Class: urn:content-classes:message
    >Importance: normal
    >Priority: normal
    >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    >Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
    >NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
    >Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTCMTY1.phx.gbl!TK2MSFTNGXA03.phx.gbl
    >Xref: TK2MSFTNGXA02.phx.gbl

    microsoft.public.dotnet.framework.aspnet.webservices:28345
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
    >
    >I encountered a problem caused by calling a web method and returning a
    >derived class one of whose property overrides its base property.
    >
    >Definitions of the two classes are as follows:
    > public class Class1
    > {
    > public Class1()
    > {
    > }
    >
    > public string Name;
    > }
    >
    > public class Class2 : Class1
    > {
    > public Class2()
    > {
    > }
    >
    > public new string[] Name;
    > }
    >
    >the web method is as follows:
    > [WebMethod]
    > public Class2 Test()
    > {
    > return new Class2();
    > }
    >
    >I can compile it correctly, however, an exception was thrown when

    referring
    >the web service:
    >
    >Member Class2.Name of type System.String[] hides base class member
    >Class1.Name of type System.String. Use XmlElementAttribute or
    >XmlAttributeAttribute to specify a new name.
    >
    >I don't know how to use XmlAttributeAttribute or
    >XmlElementAttributeAttribute class to solve the problem, but I tried the
    >following style and failed:
    >
    > [XmlElement("Class2Name", typeof(string[])),
    > XmlElement("Class1Name", typeof(string))]
    > public new string[] Name;
    >
    >Any ideas will be greatly appreciately and thanks in advance.
    >
     
    Dan Rogers, Mar 7, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TaeHo Yoo
    Replies:
    2
    Views:
    373
    TaeHo Yoo
    Jul 29, 2003
  2. tristant

    Can ASP.Net be accessed from linux ?

    tristant, Aug 5, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    795
  3. Michael A. Vickers
    Replies:
    3
    Views:
    844
    Michael A. Vickers
    Nov 25, 2004
  4. Phuff
    Replies:
    1
    Views:
    277
    Mark Fitzpatrick
    Nov 3, 2006
  5. Dave Capper

    My .Net Wrapper Class Fails when accessed with a Web Service

    Dave Capper, Sep 10, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    153
    Dave Capper
    Sep 10, 2003
Loading...

Share This Page