请问WCF的FaultException 支持互操作与Java Web服务故障
题
我写了一个Java的Axis2 1.4.1 Web服务和.NET 3.5 WCF客户端和我试图赶上抛出的WSDL故障。
不同于.NET 2.0 NET 3.5权利要求书,以支持wsdl:fault
和服务引用向导不会产生在所有的客户端代理的正确故障类。但是,当我试图抓住一个故障似乎不正确序列化,这样我只能catch (FaultException ex)
,而不是我实际使用FaultException<T>
扔类型
我看看我的reference.cs我可以看到里面的向导添加了正确FaultContract
到我opeation。
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://www.mycomp.com/wsdl/Foo", ConfigurationName="FooServiceProxy.Foo")]
public interface Foo {
[System.ServiceModel.OperationContractAttribute(Action="http://www.mycomp.com/Foo/list", ReplyAction="*")]
[System.ServiceModel.FaultContractAttribute(typeof(TestWsdlFaultsApp.FooServiceProxy.SimpleFault), Action="http://www.mycomp.com/Foo/list", Name="simpleFault")]
[System.ServiceModel.XmlSerializerFormatAttribute()]
TestWsdlFaultsApp.FooServiceProxy.listResponse list(TestWsdlFaultsApp.FooServiceProxy.listRequest request);
}
有没有别的东西,我需要在.net中做的就是这个工作?或不WCF只从.NET Web服务支持自定义WSDL错误?
下面有我的WSDL
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="wsdl-viewer.xsl"?>
<wsdl:definitions name="FooImplDefinitions"
targetNamespace="http://www.mycomp.com/wsdl/Foo"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.mycomp.com/wsdl/Foo"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- TYPES -->
<wsdl:types>
<xs:schema targetNamespace="http://www.mycomp.com/wsdl/Foo"
elementFormDefault="qualified" attributeFormDefault="unqualified"
xmlns:security="http://www.mycomp.com/xsd/types/Security">
<!-- IMPORTS -->
<xs:import namespace="http://www.mycomp.com/xsd/types/Foo"
schemaLocation="Foo.xsd" />
<xs:import namespace="http://www.mycomp.com/xsd/types/Security"
schemaLocation="Security.xsd" />
<!-- HEADER ELEMENTS -->
<xs:element name="identity" type="security:TrustedIdentity" />
<!-- REQUEST/RESPONSE ELEMENTS -->
<xs:element name="listRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="action" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="listResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="stuff" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- FAULT TYPES -->
<xs:complexType name="SimpleFault">
<xs:sequence>
<xs:element name="reason" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<!-- FAULT ELEMENTS -->
<xs:element name="simpleFault" type="tns:SimpleFault"/>
</xs:schema>
</wsdl:types>
<!-- MESSAGES -->
<wsdl:message name="listRequest">
<wsdl:part element="tns:listRequest" name="parameters" />
<wsdl:part element="tns:identity" name="header" />
</wsdl:message>
<wsdl:message name="listResponse">
<wsdl:part element="tns:listResponse" name="return" />
</wsdl:message>
<wsdl:message name="simpleException">
<wsdl:part element="tns:simpleFault" name="fault"/>
</wsdl:message>
<!-- PORT TYPES -->
<wsdl:portType name="Foo">
<wsdl:operation name="list">
<wsdl:input message="tns:listRequest" />
<wsdl:output message="tns:listResponse" />
<wsdl:fault name="simpleFault" message="tns:simpleException" />
</wsdl:operation>
</wsdl:portType>
<!-- BINDINGS -->
<wsdl:binding name="FooBinding" type="tns:Foo">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="list">
<soap:operation soapAction="http://www.mycomp.com/Foo/list" />
<wsdl:input>
<soap:header message="tns:listRequest" part="header" use="literal" />
<soap:body parts="parameters" use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="simpleFault">
<soap:fault name="simpleFault" use="literal" />
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<!-- SERVICES -->
<wsdl:service name="FooServiceImpl">
<wsdl:port name="FooPort" binding="tns:FooBinding">
<soap:address
location="http://localhost:9001/Foo/FooServiceImpl" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
解决方案 3
感谢约翰,你让我在正确的道路上,问题是显而易见的:我没有设置细节,当我在Java(Axis2中)扔了故障。
躲闪CODE:
throw new SimpleException("SimpleFault thrown");
工作的代码:
SimpleFault fault = new SimpleFault();
fault.setReason("SimpleFault reason");
SimpleFaultE faultMessage = new SimpleFaultE();
faultMessage.setSimpleFault(fault);
SimpleException ex = new SimpleException("SimpleFault thrown");
ex.setFaultMessage(faultMessage);
throw ex;
所以AXIS2 - > WCF WSDL:故障互操作工作得很好...
其他提示
WCF应与Axis2的异常工作。我已经工作,但我不记得所有的细节。
当您使用SOAP监视器或类似的东西,你怎么在故障邮件正文见?
如果你不追赶FaultException<T>
,这意味着你可能不发送。小心的正在使用的XML命名空间。看看您发送的信息,使用招或类似的东西。
FaultException<T>
正常工作与Java中,或甚至与WCF。
不隶属于 StackOverflow