开发者

Custom SOAP Fault has wrong namespace http://schemas.datacontract.org/2004/07/

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:开发者_如何学Python

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">
           <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


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 {
....
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜