WCF: WSDL-first approach: Problems with generating fault types

Posted by Juri on Stack Overflow See other posts from Stack Overflow or by Juri
Published on 2010-03-16T14:22:47Z Indexed on 2010/03/16 14:26 UTC
Read the original article Hit count: 630

Filed under:
|
|
|
|

Hi,

I'm currently in the process of creating a WCF webservice which should be compatible with WS-I Basic Profile 1.1. I'm using a wsdl-first approach (actually for the first time), defining first the xsd for the complex types, the WSDL and then using svcutil.exe for generating the according server as well as client-side interfaces/proxies. So far everything works fine. Then I decided to add a fault to my WSDL.

Regenerating with svcutil succeeded, but then I noticed that my generated fault doesn't have the properties I defined in my xsd file (which is imported by my WSDL).

Fault XSD definition

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://product.mycompany.com/groupsfault_v1.xsd"
    xmlns:tns="http://product.mycompany.com/groupsfault_v1.xsd">
    <complexType name="groupsFault">
        <sequence>
            <element name="code" type="int"/>
            <element name="message" type="string"/>
        </sequence>
    </complexType>
</schema>

Generated .Net fault object

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Xml.Serialization.XmlSchemaProviderAttribute("ExportSchema")]
[System.Xml.Serialization.XmlRootAttribute(IsNullable=false)]
public partial class groupFault : object, System.Xml.Serialization.IXmlSerializable
{

    private System.Xml.XmlNode[] nodesField;

    private static System.Xml.XmlQualifiedName typeName = new System.Xml.XmlQualifiedName("groupFault", "http://sicp.services.siag.it/groups_v1.wsdl");

    public System.Xml.XmlNode[] Nodes
    {
        get
        {
            return this.nodesField;
        }
        set
        {
            this.nodesField = value;
        }
    }

    public void ReadXml(System.Xml.XmlReader reader)
    {
        this.nodesField = System.Runtime.Serialization.XmlSerializableServices.ReadNodes(reader);
    }

    public void WriteXml(System.Xml.XmlWriter writer)
    {
        System.Runtime.Serialization.XmlSerializableServices.WriteNodes(writer, this.Nodes);
    }

    public System.Xml.Schema.XmlSchema GetSchema()
    {
        return null;
    }

    public static System.Xml.XmlQualifiedName ExportSchema(System.Xml.Schema.XmlSchemaSet schemas)
    {
        System.Runtime.Serialization.XmlSerializableServices.AddDefaultSchema(schemas, typeName);
        return typeName;
    }
}

Is this ok?? I'd expect to have an object created that contains properties for "code" and "message" s.t. you can then throw it by using something like

...
throw new FaultException<groupFault>(new groupFault { code=100, message="error" });
...

(sorry for the lower-case type definitions, but this is generated code from the WSDL)

Why doesn't the svcutil.exe generate those properties?? Some sources on the web suggested to add the /useSerializerForFaults option. I tried it, it doesn't work giving me an exception that the fault type is missing on the wsdl:portType declaration. Validation with several other tools succeeded however.

Any help is VERY appreciated :) thx

© Stack Overflow or respective owner

Related posts about wsdl

Related posts about wcf