To demonstrate the problem, let's take a look at the generated Reference.cs:
public partial class getSalesItemsV3 {
Note that these elements have the same name ( start ) and the same namespace declared by the MessageBodyMember attribute ( "" , empty namespace). This reason “The top XML element” runs “from the namespace“ refers to various types. ”Serializer exception.
If we have this option:
(b) the changes I can make to the generated proxies to make Serializer happy
... we can set namespaces for the start , end and return elements (all of which cause problems) manually. I did it myself and set the result here . You can embed it in your Reference.cs and serializer fix.
But it seems that the main reason for your problem is that this service ( http://services.hotschedules.com/api/services/SalesService?wsdl ) is intended to be used through WebServices (and this problem is a kind of incompatibility).
If you added a link to this server as a web link ( Add → Service Guide ... → More ... → Add Web Link ... ) and write the same call to the web method, no serialization problems will not arise. In fact, in my case, I got another kind of server exception in my test case, but it will solve your problem with immediate serialization.
A mirror copy of your code, but using the web service directory (and not requiring any changes to the generated files), can be found here .
Hope this helps.
UPDATE . To find the cause of this problem, we need to deeply study the source code of XmlReflectionImporter . First, our WSDL using XSD schemes for defining namespaces: http://www.w3.org/2001/XMLSchema for xsd and http://services.hotschedules.com/api/services/SalesService for tns . XmlReflectionImporter using a NameTable (this is a wrapper for a Hashtable ) to store " accessories ." An accessor is a pair of Namespace and Name .
See the source code that throws the exception:
private Accessor ReconcileAccessor(Accessor accessor, NameTable accessors) { // initial check skipped // look for accessor by name and namespace, add to accessors hash if not found and return Accessor accessor1 = (Accessor) accessors[accessor.Name, accessor.Namespace]; if (accessor1 == null) { accessor.IsTopLevelInSchema = true; accessors.Add(accessor.Name, accessor.Namespace, (object) accessor); return accessor; } // accessor ("start" in our case) found! // check if mappings is the same and return accessor. This is not our case, we have two accessors with the same name but different mappings (despite that this mappings is have the same type)! if (accessor1.Mapping == accessor.Mapping) return accessor1; // next I skipped some reconciliations for MembersMapping and ArrayMapping. Please note that it performed by types, for example: // if (accessor.Mapping is ArrayMapping) { /* some logic */} // Our mapping is not MembersMapping or ArrayMapping and we finally got there: throw new InvalidOperationException(Res.GetString("XmlCannotReconcileAccessor", (object) accessor.Name, (object) accessor.Namespace, (object) XmlReflectionImporter.GetMappingName((Mapping) accessor1.Mapping), (object) XmlReflectionImporter.GetMappingName((Mapping) accessor.Mapping))); // Resource definition is: XmlCannotReconcileAccessor=The top XML element '{0}' from namespace '{1}' references distinct types {2} and {3}. Use XML attributes to specify another XML name or namespace for the element or types. // using this resource template you can see that string representations of mappings are "WsdlDuplicateName.SalesItemService.hsSimpleDate" and "System.DateTime". }
So, the basic logic of matching we cannot have two accessories with the same name, but with different namespaces ! There may be some exceptions for the MembersMapping and ArrayMapping , but this is not our case.
I think this is some kind of mistake. The WSDL is correct and will pass the test, but due to this general implementation of the ReconcileAccessor class from XmlReflectionImporter we got an exception. Not sure if this is the exact problem of the XmlReflectionImporter , or another problem may occur at a higher abstract level. And the source created using the "Web Reference" does not use XmlReflectionImporter .
One more note: the generator sets the Namespace="" value for MessageBodyMemberAttribute, which actually disrupts the negotiation process. Therefore, I believe that there is some inconsistency or incompatibility.