难道WCF的FaultException< T>支持互操作与Java Web服务故障 [英] Does WCF FaultException<T> support interop with a Java web service Fault

查看:113
本文介绍了难道WCF的FaultException< T>支持互操作与Java Web服务故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了Java的Axis2 1.4.1 Web服务和.NET 3.5 WCF客户端,我想抓住扔了WSDL故障。

与.NET 2.0的.NET 3.5声称支持 WSDL:故障和服务引用向导的作用生成所有的客户端代理正确的故障类。但是,当我试图抓住一个故障似乎并没有正确地连载,这样我只能赶上(FaultException异常前),而不是我居然扔使用类型的FaultException< T>

我看看里面我reference.cs我可以看到向导添加正确的 FaultContract 给我opeation。

  [系统。codeDom.Compiler.Generated codeAttribute(System.ServiceModel,3.0.0.0)]
[System.ServiceModel.ServiceContractAttribute(命名空间=htt​​p://www.mycomp.com/wsdl/Foo,ConfigurationName =FooServiceProxy.Foo)
公共接口富{

        [System.ServiceModel.OperationContractAttribute(动作=htt​​p://www.mycomp.com/Foo/list,ReplyAction =*)]
 [System.ServiceModel.FaultContractAttribute(typeof运算(TestWsdlFaultsApp.FooServiceProxy.SimpleFault),行动=htt​​p://www.mycomp.com/Foo/list,NAME =simpleFault)
        [System.ServiceModel.XmlSerializerFormatAttribute()]
        TestWsdlFaultsApp.FooServiceProxy.listResponse列表(TestWsdlFaultsApp.FooServiceProxy.listRequest要求);
    }
 

有没有别的东西,我需要做的,.NET来得到这个工作?还是WCF只能从.NET Web服务支持自定义WSDL错误?

这是我的WSDL

 < XML版本=1.0编码=UTF-8&GT?;
<?xml样式表的类型=文/ XSL的href =WSDL-viewer.xsl>
< WSDL:定义名称=FooImplDefinitions
      目标名称=htt​​p://www.mycomp.com/wsdl/Foo
      XMLNS:肥皂=htt​​p://schemas.xmlsoap.org/wsdl/soap/
      的xmlns:TNS =htt​​p://www.mycomp.com/wsdl/Foo
      的xmlns:WSDL =htt​​p://schemas.xmlsoap.org/wsdl/
      的xmlns:XS =htt​​p://www.w3.org/2001/XMLSchema>

      <! - 类型 - >
      < WSDL:类型>
            < XS:模式的targetNamespace =htt​​p://www.mycomp.com/wsdl/Foo
                  将elementFormDefault =合格attributeFormDefault =不合格
                  的xmlns:安全=htt​​p://www.mycomp.com/xsd/types/Security>

                  <! - 进口 - >
                  < XS:导入命名空间=htt​​p://www.mycomp.com/xsd/types/Foo
                        的schemaLocation =Foo.xsd/>
                   < XS:导入命名空间=htt​​p://www.mycomp.com/xsd/types/Security
                        的schemaLocation =Security.xsd/>

                  <! - 头元素 - >
                  < XS:元素的名称=身份TYPE =安全:TrustedIdentity/>

                  <! - 请求/响应元素 - >
                  < XS:元素的名称=listRequest>
                        < XS:复杂类型>
                              < XS:序列>
                                    < XS:元素的名称=动作类型=XS:字符串/>
                              < / XS:序列>
                        < / XS:复杂类型>
                  < / XS:组件>
                  < XS:元素的名称=listResponse>
                        < XS:复杂类型>
                              < XS:序列>
                                    < XS:元素的名称=东西类型=XS:字符串/>
                              < / XS:序列>
                        < / XS:复杂类型>
                  < / XS:组件>

                  <! - 故障类型 - >
                  < XS:复杂类型的名称=SimpleFault>
                        < XS:序列>
                              < XS:元素的名称=理由TYPE =XS:字符串/>
                        < / XS:序列>
                  < / XS:复杂类型>

                  <! -  fault元素 - >
                  < XS:元素的名称=simpleFaultTYPE =TNS:SimpleFault/>
            < / XS:模式>
      < / WSDL:类型>

      <! - 消息 - >
      < WSDL:消息名称=listRequest>
            < WSDL:part元素=TNS:listRequestNAME =参数/>
            < WSDL:part元素=TNS:身份NAME =标题/>
      < / WSDL:消息>
      < WSDL:消息名称=listResponse>
            < WSDL:part元素=TNS:listResponseNAME =回归/>
      < / WSDL:消息>
      < WSDL:消息名称=simpleException>
            < WSDL:part元素=TNS:simpleFaultNAME =故障/>
      < / WSDL:消息>

      <! - 端口类型 - >
      < WSDL:portType的名称=富>
            < WSDL:操作名称=名单>
                  < WSDL:输入消息=TNS:listRequest/>
                  < WSDL:输出消息=TNS:listResponse/>
                  < WSDL:故障名称=simpleFault消息=TNS:simpleException/>
            < / WSDL:操作>
      < / WSDL:端口类型>

      <! - 绑定 - >
      < WSDL:绑定名称=FooBindingTYPE =TNS:富>
            <肥皂:绑定样式=文件传输=htt​​p://schemas.xmlsoap.org/soap/http/>
            < WSDL:操作名称=名单>
                  <肥皂:操作的soapAction =htt​​p://www.mycomp.com/Foo/list/>
                  < WSDL:输入>
                        <肥皂:头消息=TNS:listRequest的一部分=头利用=文字/>
                        <肥皂:身体部位=参数使用=文字/>
                  < / WSDL:输入>
                  < WSDL:输出>
                        <肥皂:身体使用=文字/>
                  < / WSDL:输出>
                  < WSDL:故障名称=simpleFault>
                        <肥皂:故障名称=simpleFault使用=文字/>
                  < / WSDL:故障>
            < / WSDL:操作>
      < / WSDL:绑定>

      <! - 服务 - >
      < WSDL:服务名称=FooServiceImpl>
            < WSDL:端口名称=FooPort绑定=TNS:FooBinding>
                  <肥皂:地址
                        位置=HTTP://本地主机:9001 /美孚/ FooServiceImpl/>
            < / WSDL:端口>
      < / WSDL:服务>

< / WSDL:定义>
 

解决方案

感谢约翰,你在正确的道路上设置了我,问题是显而易见的:我没有设定的细节时,我在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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆