views:

491

answers:

1

I'm getting this error from Mono's wsdl utility while trying to process eBay's WSDL file -

( http://developer.ebay.com/webservices/latest/eBaySvc.wsdl )

$ wsdl eBaySvc.wsdl 
Web Services Description Language Utility
Mono Framework v2.0.50727.1433
Error: XmlSchema error: Ambiguous element label which is contained by -any- particle was detected: urn:ebay:apis:eBLBaseComponents:PreferenceLevel Related schema item SourceUri: file:///home/manger/projects/ebay/eBaySvc.orig.wsdl, Line 10296, Position 7.
Stack:
   at System.Xml.Schema.ValidationHandler.RaiseValidationEvent (System.Xml.Schema.ValidationEventHandler handle, System.Exception innerException, System.String message, System.Xml.Schema.XmlSchemaObject xsobj, System.Object sender, System.String sourceUri, XmlSeverityType severity) [0x00000] 
  at System.Xml.Schema.XmlSchemaObject.error (System.Xml.Schema.ValidationEventHandler handle, System.String message, System.Exception innerException, System.Xml.Schema.XmlSchemaObject xsobj, System.Object sender) [0x00000] 
  at System.Xml.Schema.XmlSchemaObject.error (System.Xml.Schema.ValidationEventHandler handle, System.String message) [0x00000]

Searching Google for solutions reveals a suggestion of changing elements that start with <xs:any ... to <xs:any namespace="##other" ... - this certainly makes Mono's wsdl utility able to process the file, to make a .cs file out of it. But then I get a runtime exception from my C# program when I try to instantiate the webservice helper class ( eBayAPIInterfaceService service = new eBayAPIInterfaceService(); ) :

Unhandled Exception: System.InvalidOperationException: There was an error reflecting type 'AddDisputeRequestType'. ---> System.InvalidOperationException: There was an error reflecting field 'DetailLevel'. ---> System.InvalidOperationException: There was an error reflecting type 'DetailLevelCodeType'. ---> System.InvalidOperationException: There was an error reflecting type 'System.Object'. ---> System.InvalidOperationException: There was an error reflecting type 'AbstractResponseType'. ---> System.InvalidOperationException: There was an error reflecting field 'Errors'. ---> System.InvalidOperationException: There was an error reflecting type 'ErrorType'. ---> System.InvalidOperationException: There was an error reflecting field 'ErrorParameters'. ---> System.InvalidOperationException: There was an error reflecting type 'ErrorParameterType'. ---> System.InvalidOperationException: There was an error reflecting field 'Any'. ---> System.InvalidOperationException: The element Any has been attributed with an XmlAnyElementAttribute and a namespace '', but no name. When a namespace is supplied, a name is also required. Supply a name or remove the namespace.                                           
  at System.Xml.Serialization.XmlReflectionImporter.ImportAnyElementInfo (System.String defaultNamespace, System.Xml.Serialization.XmlReflectionMember rmember, System.Xml.Serialization.XmlTypeMapMemberElement member, System.Xml.Serialization.XmlAttributes atts) [0x00000]                                                                                            
  at System.Xml.Serialization.XmlReflectionImporter.CreateMapMember (System.Type declaringType, System.Xml.Serialization.XmlReflectionMember rmember, System.String defaultNamespace) [0x00000]                                                   
  at System.Xml.Serialization.XmlReflectionImporter.ImportClassMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00000]                                     
  --- End of inner exception stack trace ---

Is Mono's wsdl tool at fault here, or eBay's WSDL/schema? - several forum posts I've seen say that the WSDL doesn't match the schema, so Mono is doing the right thing, but how do I fix it so I can instantiate the webservice helper class from C#?

Versions of my tools :

$ wsdl Web Services Description Language Utility Mono Framework v2.0.50727.1433

$ gmcs --version Mono C# compiler version 2.4.2.3

Generated code for ErrorParameterType :

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.1433")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:ebay:apis:eBLBaseComponents")]
public partial class ErrorParameterType {

    private System.Xml.XmlElement[] anyField165;

    ... more class members follow ...

    /// <remarks/>
    [System.Xml.Serialization.XmlAnyElement(Namespace="")]
    public System.Xml.XmlElement[] Any {
        get {
            return this.anyField165;
        }
        set {
            this.anyField165 = value;
        }
    }
}

The eBayAPIInterfaceService.cs file which wsdl generates after my 'fix' is here

+1  A: 

I don't know if this solves your problem, but the xs:any wildcard in your question is missing two '#':

<xs:any namespace="##other" ...
                   ↑


The generated C# code contains lots of definitions like this:

[System.Xml.Serialization.XmlAnyElement(Namespace="")]
public System.Xml.XmlElement[] Any {
    get {
        return this.anyFieldXXX;
    }
    set {
        this.anyFieldXXX = value;
    }
}

From MSDN:

Apply the XmlAnyElementAttribute to a field that returns an array of XmlElement or XmlNode objects. Such a field can be used in two ways, depending on whether an object is being serialized or deserialized. When serialized, the object is generated as XML elements or nodes, even though they have no corresponding member (or members) in the object being serialized. If you specify a Name property value when applying the attribute, all XmlElement or XmlNode objects inserted into the array must have the same element name and default namespace, or an exception is thrown. If you set the Namespace property value, you must set the Name property as well, and the XmlElement or XmlNode objects must also have the same name and namespace values. If no Name value is specified, the XmlElement or XmlNode objects can have any element name.

So I'd guess the solution is to simply remove the Namespace property values:

[System.Xml.Serialization.XmlAnyElement]
dtb
good spotting - that was a typo which I made, i did actually try "##other" - which made the wsdl tool happy, but I still got the runtime exception when running my simple C# program to instantiate the webservice helper class
matja
@dtb : thanks for the suggestion about removing the Namespace property values, that certainly seems to fix the runtime exception I was getting, but now I get a new runtime exception : "Unhandled Exception: System.InvalidOperationException: Member RequesterCredentialsField not found in class eBayAPIInterfaceService." - Which is weird because RequesterCredentialsField is the first member in eBayAPIInterfaceService. I don't understand why it is not finding it.
matja
The `RequesterCredentialsField` field is private. XmlSerialization works only with public properties/fields, i.e. it should use the public `RequesterCredentials` property instead of the private field.
dtb
Thankyou, removing the namespace from the generated XmlAnyElement properties and using a public RequesterCredentialsField worked perfect.
matja