Web reference/Proxy class problems with custom objects

Discussion in 'ASP .Net Web Services' started by Joe, May 5, 2004.

  1. Joe

    Joe Guest

    I have built a webservice which consumes and returns a custom object/class which was generated using XSD.exe from an XML schema. When WSDL.exe generates a proxy class describing the webservice the autogenerated proxy code (generated by WSDL.exe) leaves the namespace and root node definition of the custom object out. When I want to use the proxy class and/or the webreference an exception is thrown because there is no namespace on the root node of the object which is trying to serialize/deserialize to the webmethod. To successfully call the webmethod I have to add a line to the proxy class which is generated by WSDL.exe or via a webreference, it seems the custom object definition is imported into the proxy class and leaves the root node namespace off the object

    Here is the example from within the proxy class, "Entities" is the name of the root node of the custom object generated using XSD.ex

    This is what is auto-generated within the proxy clas

    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://MySchema.Name";)
    public class Entities


    I cannot call the webmethod successfully from a console applciation unless I add the following to it (second line)

    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://MySchema.Name";)
    [System.Xml.Serialization.XmlRoot(Namespace"http://MySchema.Name";)]
    public class Entities


    O

    I can add the following piece of code to the console application and successfully call the webmetho

    > XmlRootAttribute xmlRoot = new XmlRootAttribute()
    > XmlAttributes attrs = new XmlAttributes()
    > XmlAttributeOverrides overrides = new XmlAttributeOverrides()
    > xmlRoot.Namespace = "http://MySchema.Name"
    > attrs.XmlRoot = xmlRoot
    > overrides.Add(typeof(KeyIDAccess.Entities), attrs)
    > serializer = new XmlSerializer(typeof(KeyIDAccess.Entities), overrides)


    Thanks for the help let me know if you need more info, the basics of it is I cannot call a webmethod using a custom object
    -Jo
    Joe, May 5, 2004
    #1
    1. Advertising

  2. the custom type that you generated from the XSD. . .
    Is this type being shared across client and server?
    In this case, what you want to do is modify the code generated by wsdl.exe
    or "add web ref"
    to replace the generated type there with your previously generated (shared)
    type.

    Does this solve the problem?

    also see
    http://msdn.microsoft.com/library/en-us/dnservice/html/service07162002.asp
    for some info on sharing types.

    -Dino


    "Joe" <> wrote in message
    news:...
    >
    > I have built a webservice which consumes and returns a custom object/class

    which was generated using XSD.exe from an XML schema. When WSDL.exe
    generates a proxy class describing the webservice the autogenerated proxy
    code (generated by WSDL.exe) leaves the namespace and root node definition
    of the custom object out. When I want to use the proxy class and/or the
    webreference an exception is thrown because there is no namespace on the
    root node of the object which is trying to serialize/deserialize to the
    webmethod. To successfully call the webmethod I have to add a line to the
    proxy class which is generated by WSDL.exe or via a webreference, it seems
    the custom object definition is imported into the proxy class and leaves the
    root node namespace off the object.
    >
    > Here is the example from within the proxy class, "Entities" is the name of

    the root node of the custom object generated using XSD.exe
    >
    > This is what is auto-generated within the proxy class
    >
    >

    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://MySchema.Name";
    )]
    > public class Entities {
    > }
    >
    > I cannot call the webmethod successfully from a console applciation unless

    I add the following to it (second line).
    >
    >

    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://MySchema.Name";
    )]
    > [System.Xml.Serialization.XmlRoot(Namespace"http://MySchema.Name";)]
    > public class Entities {
    > }
    >
    >
    > OR
    >
    > I can add the following piece of code to the console application and

    successfully call the webmethod
    >
    > > XmlRootAttribute xmlRoot = new XmlRootAttribute();
    > > XmlAttributes attrs = new XmlAttributes();
    > > XmlAttributeOverrides overrides = new XmlAttributeOverrides();
    > > xmlRoot.Namespace = "http://MySchema.Name";
    > > attrs.XmlRoot = xmlRoot;
    > > overrides.Add(typeof(KeyIDAccess.Entities), attrs);
    > > serializer = new XmlSerializer(typeof(KeyIDAccess.Entities), overrides);

    >
    >
    > Thanks for the help let me know if you need more info, the basics of it is

    I cannot call a webmethod using a custom object.
    > -Joe
    >
    >
    >
    >
    >
    Dino Chiesa [Microsoft], May 5, 2004
    #2
    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. Amine Zejli
    Replies:
    1
    Views:
    392
    Juan Wajnerman
    Oct 19, 2003
  2. 7stud
    Replies:
    11
    Views:
    674
    Dennis Lee Bieber
    Mar 20, 2007
  3. John J. Lee
    Replies:
    7
    Views:
    312
    John J. Lee
    Nov 27, 2007
  4. Mark Thomson

    Sending Objects / Proxy Class Question

    Mark Thomson, Jul 25, 2005, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    116
    Michael Nemtsev
    Jul 25, 2005
  5. phil2phil

    having problems with webservice (proxy) reference

    phil2phil, Aug 12, 2005, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    102
    ArunPrakash
    Aug 13, 2005
Loading...

Share This Page