难道WCF的FaultException&LT; T&GT;支持互操作与Java Web服务故障 [英] Does WCF FaultException<T> support interop with a Java web service Fault
问题描述
我已经写了Java的Axis2 1.4.1 Web服务和.NET 3.5 WCF客户端,我想抓住扔了WSDL故障。
与.NET 2.0的.NET 3.5声称支持 WSDL:故障
和服务引用向导的作用生成所有的客户端代理正确的故障类。但是,当我试图抓住一个故障似乎并没有正确地连载,这样我只能赶上(FaultException异常前)
,而不是我居然扔使用类型的FaultException&LT; T&GT;
我看看里面我reference.cs我可以看到向导添加正确的 FaultContract
给我opeation。
[系统。codeDom.Compiler.Generated codeAttribute(System.ServiceModel,3.0.0.0)]
[System.ServiceModel.ServiceContractAttribute(命名空间=http://www.mycomp.com/wsdl/Foo,ConfigurationName =FooServiceProxy.Foo)
公共接口富{
[System.ServiceModel.OperationContractAttribute(动作=http://www.mycomp.com/Foo/list,ReplyAction =*)]
[System.ServiceModel.FaultContractAttribute(typeof运算(TestWsdlFaultsApp.FooServiceProxy.SimpleFault),行动=http://www.mycomp.com/Foo/list,NAME =simpleFault)
[System.ServiceModel.XmlSerializerFormatAttribute()]
TestWsdlFaultsApp.FooServiceProxy.listResponse列表(TestWsdlFaultsApp.FooServiceProxy.listRequest要求);
}
有没有别的东西,我需要做的,.NET来得到这个工作?还是WCF只能从.NET Web服务支持自定义WSDL错误?
这是我的WSDL
&LT; XML版本=1.0编码=UTF-8&GT?;
&LT;?xml样式表的类型=文/ XSL的href =WSDL-viewer.xsl&GT;
&LT; WSDL:定义名称=FooImplDefinitions
目标名称=http://www.mycomp.com/wsdl/Foo
XMLNS:肥皂=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&GT;
&LT;! - 类型 - &GT;
&LT; WSDL:类型&GT;
&LT; XS:模式的targetNamespace =http://www.mycomp.com/wsdl/Foo
将elementFormDefault =合格attributeFormDefault =不合格
的xmlns:安全=http://www.mycomp.com/xsd/types/Security&GT;
&LT;! - 进口 - &GT;
&LT; XS:导入命名空间=http://www.mycomp.com/xsd/types/Foo
的schemaLocation =Foo.xsd/&GT;
&LT; XS:导入命名空间=http://www.mycomp.com/xsd/types/Security
的schemaLocation =Security.xsd/&GT;
&LT;! - 头元素 - &GT;
&LT; XS:元素的名称=身份TYPE =安全:TrustedIdentity/&GT;
&LT;! - 请求/响应元素 - &GT;
&LT; XS:元素的名称=listRequest&GT;
&LT; XS:复杂类型&GT;
&LT; XS:序列&GT;
&LT; XS:元素的名称=动作类型=XS:字符串/&GT;
&LT; / XS:序列&GT;
&LT; / XS:复杂类型&GT;
&LT; / XS:组件&gt;
&LT; XS:元素的名称=listResponse&GT;
&LT; XS:复杂类型&GT;
&LT; XS:序列&GT;
&LT; XS:元素的名称=东西类型=XS:字符串/&GT;
&LT; / XS:序列&GT;
&LT; / XS:复杂类型&GT;
&LT; / XS:组件&gt;
&LT;! - 故障类型 - &GT;
&LT; XS:复杂类型的名称=SimpleFault&GT;
&LT; XS:序列&GT;
&LT; XS:元素的名称=理由TYPE =XS:字符串/&GT;
&LT; / XS:序列&GT;
&LT; / XS:复杂类型&GT;
&LT;! - fault元素 - &GT;
&LT; XS:元素的名称=simpleFaultTYPE =TNS:SimpleFault/&GT;
&LT; / XS:模式&GT;
&LT; / WSDL:类型&GT;
&LT;! - 消息 - &GT;
&LT; WSDL:消息名称=listRequest&GT;
&LT; WSDL:part元素=TNS:listRequestNAME =参数/&GT;
&LT; WSDL:part元素=TNS:身份NAME =标题/&GT;
&LT; / WSDL:消息&GT;
&LT; WSDL:消息名称=listResponse&GT;
&LT; WSDL:part元素=TNS:listResponseNAME =回归/&GT;
&LT; / WSDL:消息&GT;
&LT; WSDL:消息名称=simpleException&GT;
&LT; WSDL:part元素=TNS:simpleFaultNAME =故障/&GT;
&LT; / WSDL:消息&GT;
&LT;! - 端口类型 - &GT;
&LT; WSDL:portType的名称=富&GT;
&LT; WSDL:操作名称=名单&GT;
&LT; WSDL:输入消息=TNS:listRequest/&GT;
&LT; WSDL:输出消息=TNS:listResponse/&GT;
&LT; WSDL:故障名称=simpleFault消息=TNS:simpleException/&GT;
&LT; / WSDL:操作&gt;
&LT; / WSDL:端口类型&GT;
&LT;! - 绑定 - &GT;
&LT; WSDL:绑定名称=FooBindingTYPE =TNS:富&GT;
&LT;肥皂:绑定样式=文件传输=http://schemas.xmlsoap.org/soap/http/&GT;
&LT; WSDL:操作名称=名单&GT;
&LT;肥皂:操作的soapAction =http://www.mycomp.com/Foo/list/&GT;
&LT; WSDL:输入&GT;
&LT;肥皂:头消息=TNS:listRequest的一部分=头利用=文字/&GT;
&LT;肥皂:身体部位=参数使用=文字/&GT;
&LT; / WSDL:输入&GT;
&LT; WSDL:输出&GT;
&LT;肥皂:身体使用=文字/&GT;
&LT; / WSDL:输出&GT;
&LT; WSDL:故障名称=simpleFault&GT;
&LT;肥皂:故障名称=simpleFault使用=文字/&GT;
&LT; / WSDL:故障&GT;
&LT; / WSDL:操作&gt;
&LT; / WSDL:绑定&GT;
&LT;! - 服务 - &GT;
&LT; WSDL:服务名称=FooServiceImpl&GT;
&LT; WSDL:端口名称=FooPort绑定=TNS:FooBinding&GT;
&LT;肥皂:地址
位置=HTTP://本地主机:9001 /美孚/ FooServiceImpl/&GT;
&LT; / WSDL:端口&GT;
&LT; / WSDL:服务&GT;
&LT; / WSDL:定义&GT;
感谢约翰,你在正确的道路上设置了我,问题是显而易见的:我没有设定的细节时,我在Java(Axis2中)扔了故障。
躲闪code:
抛出新SimpleException(SimpleFault抛出);
工作code:
SimpleFault故障=新SimpleFault();
fault.setReason(SimpleFault原因);
SimpleFaultE faultMessage =新SimpleFaultE();
faultMessage.setSimpleFault(故障);
SimpleException EX =新SimpleException(SimpleFault抛出);
ex.setFaultMessage(faultMessage);
抛出前;
所以AXIS2 - > WCF WSDL:故障互操作工作得很好...
I have written a java axis2 1.4.1 web service and .net 3.5 WCF client and I am trying to catch the wsdl faults thrown.
Unlike .net 2.0 the .net 3.5 claims to support wsdl:fault
and the service reference wizard does generate all the correct fault classes in the client proxy. But when I try to catch a fault it doesn't seem to correctly serialise so that I can only catch (FaultException ex)
and not the type I actually threw using FaultException<T>
I had a look inside my reference.cs I can see wizard has added correct FaultContract
to the my 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);
}
Is there something else I need to do in .net to get this to work? or does WCF only support custom wsdl faults from a .net web service ?
Heres my 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>
Thanks john you set me on the right path, Problem was obvious: I was not setting the detail when I threw the fault in java (axis2).
DODGY CODE:
throw new SimpleException("SimpleFault thrown");
WORKING CODE:
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;
So AXIS2 -> WCF wsdl:fault interop works just fine...
这篇关于难道WCF的FaultException&LT; T&GT;支持互操作与Java Web服务故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!