我编写了一个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
。
[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>
答案 0 :(得分:1)
WCF应该与axis2异常一起使用。我有它的工作,但我不记得所有的细节。
当您使用SOAP监视器或类似的东西时,您在故障消息正文中看到了什么?
答案 1 :(得分:1)
如果你没有抓住FaultException<T>
,那就意味着你可能没有发送它。注意所使用的XML命名空间。使用Fiddler或类似的东西来看看你发送的是什么。
FaultException<T>
适用于Java,甚至适用于WCF。
答案 2 :(得分:1)
感谢约翰,你让我走上了正确的道路,问题显而易见:当我在java(axis2)中抛出错误时,我没有设置细节。
DODGY 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 - &gt; WCF wsdl:fault interop工作得很好......