Web reference/Proxy class problems with custom objects

J

Joe

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
 
D

Dino Chiesa [Microsoft]

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 said:
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
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top