Prob using a custom type in asp.net webservice

Discussion in 'ASP .Net Web Services' started by Brian Steiner, Jan 18, 2005.

  1. I have the following sample asp.net webservice:

    ....
    namespace x
    {
    [WebService(Namespace="mynamespace")]
    public class WS : System.Web.Services.WebService
    {
    ...
    public class Class1
    {
    public string s;
    }
    public class Class2
    {
    public string s;
    }
    public class Class3
    {
    public string s;
    public Class1 c1;
    public Class2 c2;
    }

    public string Test(Class3 c3)
    {
    }
    }
    }

    When I use XmlSerializer to deserialize the webreference proxy for Class3,
    it includes namespace attributes for Class3.s, Class3.c1, and Class3.c2. If
    I set the namespace attribute of the webservice to "" and update the
    webreference, the webreference proxy no longer works. How can I tell the
    webservice to ignore the namespace attribute for all public types in Class3?
    Brian Steiner, Jan 18, 2005
    #1
    1. Advertising

  2. Thanks Christoph.

    I tried both of your suggestions and the autogenerated webref proxy types
    continue to define a namespace attrib. Here's an example of the webref
    proxies:

    [System.Xml.Serialization.XmlTypeAttribute(Namespace="mynamespace")]
    public class Class1
    {
    public string s;
    }

    [System.Xml.Serialization.XmlTypeAttribute(Namespace="mynamespace")]
    public class Class2
    {
    public string s;
    }

    [System.Xml.Serialization.XmlTypeAttribute(Namespace="mynamespace")]
    public class Class3
    {
    public string s;
    public Class1 c1;
    public Class2 c2;
    }

    When I deserialize the proxy class Class3 i get:

    <Class3 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <s xmlns="mynamespace"/>
    <c1 xmlns="mynamespace">
    <s/>
    </c1>
    <c2 xmlns="mynamespace">
    <s/>
    </c2>
    </Class3>

    When I deserialize the types in the webservice itself i get:

    <Class3 ...>
    <s/>
    <c1>
    <s/>
    </c1>
    <c2>
    <s/>
    </c2>
    </Class3>

    What I want to do is serialize Class3 in the webservice, deserialize it on
    the client, and then submit it to the webservice method Test. The namespace
    requirement on the proxy types is preventing me from doing this.

    "Christoph Schittko [MVP]"
    >
    > Brian,
    >
    > You can't tell the web service class to "ignore" the namespace for all
    > fields. You have to override the parent's, i.e. the web service's XML
    > namespace setting on every field.
    >
    > If you change the XML namespace settings on the web service or any of
    > the classes that occur as method parameters or return values, you always
    > have to re-generate the proxy class because you changed the XML wire
    > format. There is no way the original proxy can communicate with the
    > changed service.
    >
    > Now, for your fields of Class3 not to have any namespace declarations
    > you can:
    >
    > 1)
    > Set the namespace on Class3 with the XmlType attribute:
    >
    > [XmlType(Namespace="")]
    > public class Class3
    > {
    > public string s;
    > public Class1 c1;
    > public Class2 c2;
    > }
    >
    > Or
    >
    > 2)
    > You can define the namespace of each field individually:
    >
    > public class Class3
    > {
    > [XmlElement(Namespace="")]
    > public string s;
    > [XmlElement(Namespace="")]
    > public Class1 c1;
    > [XmlElement(Namespace="")]
    > public Class2 c2;
    > }
    >
    > HTH,
    > Christoph Schittko
    > MVP XML
    > http://weblogs.asp.net/cschittko
    >
    >
    >> -----Original Message-----
    >>
    >> I have the following sample asp.net webservice:
    >>
    >> ...
    >> namespace x
    >> {
    >> [WebService(Namespace="mynamespace")]
    >> public class WS : System.Web.Services.WebService
    >> {
    >> ...
    >> public class Class1
    >> {
    >> public string s;
    >> }
    >> public class Class2
    >> {
    >> public string s;
    >> }
    >> public class Class3
    >> {
    >> public string s;
    >> public Class1 c1;
    >> public Class2 c2;
    >> }
    >>
    >> public string Test(Class3 c3)
    >> {
    >> }
    >> }
    >> }
    >>
    >> When I use XmlSerializer to deserialize the webreference proxy for

    > Class3,
    >> it includes namespace attributes for Class3.s, Class3.c1, and

    > Class3.c2.
    >> If
    >> I set the namespace attribute of the webservice to "" and update the
    >> webreference, the webreference proxy no longer works. How can I tell

    > the
    >> webservice to ignore the namespace attribute for all public types in
    >> Class3?

    >
    >
    Brian Steiner, Jan 20, 2005
    #2
    1. Advertising

  3. Brian Steiner

    Elroyskimms Guest

    Christoph,

    I've been looking for an answer to an ASP.Net problem and have not had
    much luck. I've also seen you respond to similar issues as mine and at
    least once, come very to close to answering the question. If you
    wouldn't mind, could you please take a look at the following thread:

    http://www.developersdex.com/vb/message.asp?r=3760455&p=1121
    Thanks in advance for your help,

    -Elroyskimms
    Elroyskimms, Jan 21, 2005
    #3
    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. josephrthomas

    ASP.NET prob...(using VB.NET)

    josephrthomas, Dec 22, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    479
    Anders Sundberg
    Dec 22, 2003
  2. jophrthomas

    VB.NET ASP.NET prob

    jophrthomas, Dec 23, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    471
    David Wier
    Dec 23, 2003
  3. jophrthomas

    VB.NET ASP.NET prob

    jophrthomas, Dec 23, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    2,756
    Jim Cheshire [MSFT]
    Dec 23, 2003
  4. Guest
    Replies:
    0
    Views:
    364
    Guest
    Jun 7, 2004
  5. Josephine Schafer

    type prob

    Josephine Schafer, Nov 27, 2003, in forum: C++
    Replies:
    7
    Views:
    660
Loading...

Share This Page