views:

501

answers:

4

My question is about integration between a Java web service and a C# .NET client.

Service: CXF 2.2.3 with Aegis databinding Client: C#, .NET 3.5 SP1

For some reason Visual Studio generates two C# proxy enums for each Java enum. The generated C# classes do not compile.

For example, this Java enum:

public enum SqlDialect {
    GENERIC, SYBASE, SQL_SERVER, ORACLE;
}

Produces this WSDL:

<xsd:simpleType name="SqlDialect">
    <xsd:restriction base="xsd:string">
        <xsd:enumeration value="GENERIC" />
        <xsd:enumeration value="SYBASE" />
        <xsd:enumeration value="SQL_SERVER" />
        <xsd:enumeration value="ORACLE" />
    </xsd:restriction>
</xsd:simpleType>

For this WSDL Visual Studio generates two partial C# classes (generated comments removed):

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="SqlDialect", Namespace="http://somenamespace")]
public enum SqlDialect : int {

    [System.Runtime.Serialization.EnumMemberAttribute()]
    GENERIC = 0,

    [System.Runtime.Serialization.EnumMemberAttribute()]
    SYBASE = 1,

    [System.Runtime.Serialization.EnumMemberAttribute()]
    SQL_SERVER = 2,

    [System.Runtime.Serialization.EnumMemberAttribute()]
    ORACLE = 3,
}


[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3082")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://somenamespace")]
public enum SqlDialect {
    GENERIC,
    SYBASE,
    SQL_SERVER,
    ORACLE,
}

The resulting C# code does not compile:

The namespace 'somenamespace' already contains a definition for 'SqlDialect'

I will appreciate any ideas...

A: 

For certain WSDLs, I have had extra code generated (in my case, extra class members that didn't exist). This caused problems when trying to use it, so I just deleted the code I identified as excess and it started working. I'd try deleting one of the enums and seeing what happens.

hemisphire
Thank you for the suggestion. I also edited the code manually, and deleting the first of the enum classes resolved the compilation issues.However, errors in the generated code are just a sign of bigger troubles. For example:- the C# client cannot correctly un-marshall Java exceptions - any server-side exception information is lost;- null values are un-marshalled not as C# nulls, but as XmlNode objects.
Sergey
+1  A: 

I found what "makes" Visual Studio generate duplicate proxy classes... Our web service data model is polymorphic and uses abstract classes - this is essentially why we use Aegis databinding. If there is more than one abstract class in the hierarchy, Visual Studio will generate duplicate proxies.

For example, in this web service contract:

AbstractRestrictionDef getRestriction(...parameters...)

these classes would not work:

abstract class AbstractModelObject -– abstract class AbstractRestrictionDef –- class SqlRestrictionDef

but these classes would:

abstract class AbstractModelObject -– class AbstractRestrictionDef -– class ParsedRestrictionDef
Sergey
A: 

Hey, Sergey, Did you ever find a way to make svcUtil or VS stop making these duplicate classes, or are you just editing them by hand? I'm in the same situation, calling java web service from .net; the java classes have multiple abstract classes in their inheritance hierarchy, however, the java classes are out of my hands so I can't change them.

Mike
Mike - I simply removed the abstract modifier from the offending Java classes.
Sergey
A: 

Try adding the service referance as a .net 2 referance; use add service referance > advanced > add web reference...

Derek Bartram