Domanda

Ho scritto un axis2 1.4.1 servizio web Java e .NET 3.5 client WCF e sto cercando di catturare gli errori WSDL gettati.

A differenza di .NET 2.0 di .NET 3.5 afferma di sostenere wsdl:fault e la procedura guidata di riferimento al servizio fa generare tutte le classi di guasto corrette nel proxy client. Ma quando cerco di catturare un guasto che non sembra puntate correttamente in modo che posso solo catch (FaultException ex) e non il tipo di realtà ho buttato usando FaultException<T>

Ho dato un'occhiata dentro le mie Reference.cs posso vedere mago ha aggiunto corretta FaultContract alla mia 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);
    }

C'è qualcos'altro che devo fare in .NET per ottenere questo lavoro? o se WCF supporta solo i guasti WSDL personalizzato da un servizio Web .NET?

Ecco il mio 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>
È stato utile?

Soluzione 3

Grazie John mi impostato sulla strada giusta, Il problema era ovvio: non ero l'impostazione del dettaglio quando ho buttato l'errore in java (axis2).

CODICE DODGY:

throw new SimpleException("SimpleFault thrown");

CODICE DI LAVORO:

 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;

Quindi Axis2 -> WCF WSDL: colpa di interoperabilità funziona bene ...

Altri suggerimenti

WCF dovrebbe funzionare con le eccezioni asse2. Avevo farlo funzionare, ma non mi ricordo tutti i dettagli.

Quando si utilizza il monitor SOAP o qualcosa del genere, cosa vedi nel corpo del messaggio di errore?

Se non volete prendere la FaultException<T>, che significa che non stai probabilmente inviarlo. Fate attenzione del namespace XML in uso. Date un'occhiata a quello che si sta inviando, utilizzando Fiddler o qualcosa di simile.

<=> funziona bene con Java, o anche con WCF.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top