views:

14

answers:

1

Hi there I've defined a custom schema for a soap fault which looks like this: ... ...

I've genereated code in VS 2008:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3053")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.zurich.com/zsoa/corporate/common/2008/08/fault")]
[System.Xml.Serialization.XmlRootAttribute("zsoaFault", Namespace="http://schemas.zurich.com/zsoa/corporate/common/2008/08/fault", IsNullable=false)]
public partial class ZSOAFault : AbstractFault
{

...

I've developed a custom IErrorHandler (part of a framework shipped to all projects) which generates this custom soap fault like this:

Schemas.ZSOAFault.ZSOAFault zfault = new Schemas.ZSOAFault.ZSOAFault();
zfault.message = "hello";
zfault.operation = "operation";
zfault.serviceContext = "serviceContext";
zfault.serviceEndpoint = "serviceEndpoint";
zfault.timeStamp = DateTime.Now;

FaultException<Schemas.ZSOAFault.ZSOAFault> fe = new FaultException<Schemas.ZSOAFault.ZSOAFault>(zfault);        
MessageFault msgFault = fe.CreateMessageFault();

It's important that the class Schemas.ZSOAFault.ZSOAFault has been generated from the schema and not from the application wsdl which imports the same schema also.

But when I look to this returned soap fault I see a different namespace:

     <detail>
        <ZSOAFault xmlns="http://schemas.datacontract.org/2004/07/Schemas.ZSOAFault" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
           <message>hello</message>
           <exception i:nil="true"/>
           <operation>operation</operation>
           <serviceContext>serviceContext</serviceContext>
           <serviceEndpoint>serviceEndpoint</serviceEndpoint>
           <timeStamp>2010-07-14T14:31:58.5437649+02:00</timeStamp>
        </ZSOAFault>
     </detail>

I'd expected to see my namespace of the custom fault definition in the schema or am I wrong?

Thanks Oliver

+1  A: 

I seem to remember that custom faults in WCF are required to be data contracts, and never use the XmlSerializer, so those Xml serializer attributes you're using will be ignored. Instead, use the [DataContract] attribute:

[DataContract(Name="zsoaFault", Namespace="http://schemas.zurich.com/zsoa/corporate/common/2008/08/fault")]
public partial class ZSOAFault : AbstractFault {
....
}
tomasr
I've added the DataContract attribute to ZSOAFault. Now the namespace of the zsoaFault element is correct but the message element has got the generated namespace again (message is inherited from AbstractFault). I tried to add the DataContract attribut to AbstractFault also, then no message element is returned.Do I have to remove all System.Xml.Serialization attributes?
I've found the problem. The AbstractFault didn't define the message member as [DataMember]. It works now. Thanks for the help.