2011-08-24 12 views
7

मेरे पास एक तृतीय पक्ष webservice है जिसके लिए मैं wsimport का उपयोग कर क्लाइंट उत्पन्न करता हूं। Webservice के लिए प्रत्येक कॉल सफलतापूर्वक पूर्ण हो जाती है, लेकिन प्रतिक्रिया ऑब्जेक्ट जो मुझे वापस मिलती है, उसके सभी फ़ील्ड शून्य हो जाते हैं। नेटवर्क की निगरानी करना मैं देख सकता हूं कि तार पर प्रतिक्रिया संदेश में सभी एक्सएमएल तत्वों में उनके मूल्य हैं, इसलिए ऑब्जेक्ट में इसमें गैर-शून्य डेटा होना चाहिए। साथ ही, पुराने अक्ष 1 के साथ उत्पन्न एक ही सेवा के लिए एक ग्राहक और उसी डेटा के साथ बुलाया गया एक गैर-खाली प्रतिक्रिया देता है। कोई विचार क्या हो रहा है? (यदि इससे कोई फर्क पड़ता है तो मैं जेएक्सबी के मोक्सी के कार्यान्वयन का उपयोग कर रहा हूं)।मेरा जैक्स-डब्ल्यू webservice क्लाइंट केवल खाली ऑब्जेक्ट्स देता है

अद्यतन: मैं इसे कम करने में सक्षम हूं। Wsdl ऑब्जेक्ट को अपने नामस्थान में परिभाषित करता है, http://www.acme.com/ws कहें। प्रतिक्रिया मैं सेवा से मिलता है

<?xml version="1.0" encoding="UTF-8"?> 
... SOAP envelope ... 
<ns1:opINFOWLResponse xmlns:ns1="http://www.acme.com/ws" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<ns1:responseINFOWL xsi:type="ns1:responseINFOWL"> 
<result>6003</result> 
<ndserr/> 
<transid>61437594</transid> 
<descriptionerr>BLAH.</descriptionerr> 
</ns1:responseINFOWL> 
</ns1:opINFOWLResponse> 
... SOAP closing tags ... 

है और एक गैर अशक्त OpINFOWLResponse जो सभी क्षेत्रों शून्य पर सेट के साथ एक गैर अशक्त responseINFOWL वस्तु इर्द-गिर्द घूमती को unmarshalled है। सिर्फ मनोरंजन के लिए मैं ऊपर टुकड़ा unmarshal को (सोप भूमि के ऊपर अलग करना के बाद)

JAXBContext ctx = JAXBContext.newInstance(OpINFOWLResponse.class); 
Unmarshaller u = ctx.createUnmarshaller(); 

OpINFOWLResponse o = (OpINFOWLResponse) u.unmarshal(new StringReader(theSnippetAbove)); 
ResponseINFOWL w = o.getResponseINFOWL(); 

लाइनों के एक जोड़े लेखन की कोशिश की है और मैं एक ही परिणाम मिलता है। यदि मैं ऊपर एक्सएमएल को

<?xml version="1.0" encoding="UTF-8"?> 
<ns1:opINFOWLResponse xmlns:ns1="http://www.acme.com/ws" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<ns1:responseINFOWL xsi:type="ns1:responseINFOWL"> 
<ns1:result>6003</ns1:result> 
<ns1:ndserr/> 
<ns1:transid>61437594</ns1:transid> 
<ns1:descriptionerr>BLAH.</ns1:descriptionerr> 
</ns1:responseINFOWL> 
</ns1:opINFOWLResponse> 

सब कुछ ठीक काम करता है। ओह।

अद्यतन (फिर): दोनों JAXB-आरआई और Moxy के साथ भी यही व्यवहार। अभी भी पता नहीं है कि क्या गलत है।

अद्यतन (सितम्बर 9): नीचे के बारे में नाम स्थान योग्यता के गलत होने के सुझाव दिलचस्प है, लेकिन मैं माना wsimport चीजों को सही मिलेगा। वैसे भी, यह मेरा package-info.java

@XmlSchema(
namespace = "http://www.acme.com/ws", 
elementFormDefault = XmlNsForm.QUALIFIED) 
package it.sky.guidaTv.service.remote; 

import javax.xml.bind.annotation.XmlSchema; 
import javax.xml.bind.annotation.XmlNsForm; 

है और इस ResponseINFOWL वर्ग

/* 
* <p>Java class for responseINFOWL complex type. 
* 
* <p>The following schema fragment specifies the expected content contained within this class. 
* 
* <pre> 
* &lt;complexType name="responseINFOWL"> 
* &lt;complexContent> 
*  &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 
*  &lt;sequence> 
*   &lt;element name="result" type="{http://www.w3.org/2001/XMLSchema}string"/> 
*   &lt;element name="descriptionerr" type="{http://www.w3.org/2001/XMLSchema}string"/> 
*   &lt;element name="transid" type="{http://www.w3.org/2001/XMLSchema}string"/> 
*   &lt;element name="ndserr" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> 
*   &lt;element name="wallet" type="{http://www.acme.com/ws}t_wallet" minOccurs="0"/> 
*  &lt;/sequence> 
*  &lt;/restriction> 
* &lt;/complexContent> 
* &lt;/complexType> 
* </pre> 
* 
* 
*/ 
@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "responseINFOWL", propOrder = { 
"result", "descriptionerr", "transid", "ndserr", "wallet" }) 
public class ResponseINFOWL { 

@XmlElement(required = true) 
protected String result; 
@XmlElement(required = true) 
protected String descriptionerr; 
@XmlElement(required = true) 
protected String transid; 
protected String ndserr; 
protected TWallet wallet; 

    // getters, setters and all. 

} 

मैं package-info में नामस्थान लेकिन अभी भी कोई खुशी के साथ एक सा खेलने की कोशिश की है के प्रासंगिक हिस्सा है।

+0

क्या आप संदेश और कक्षाओं से नमूने प्रदान कर सकते हैं? यह मैपिंग में मिस्चैच कहां निर्धारित करने में मदद करेगा। –

+0

शायद मैं उपयुक्त रूप से अनामित wsdl फ़ाइल और टेस्ट क्लास पोस्ट कर सकता हूं, मेरे मामले में बाकी सबकुछ wsimport द्वारा उत्पन्न होता है। मजेदार बात यह है कि एक ही तीसरे पक्ष की अन्य सेवाएं ठीक काम करती हैं। – agnul

उत्तर

1

यदि मेरा उपयोग केस गलत है तो कृपया मुझे सही करें।

आप unmarshal कर सकते हैं:

<?xml version="1.0" encoding="UTF-8"?> 
<ns1:opINFOWLResponse xmlns:ns1="http://www.acme.com/ws" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <ns1:responseINFOWL xsi:type="ns1:responseINFOWL"> 
     <ns1:result>6003</ns1:result> 
     <ns1:ndserr /> 
     <ns1:transid>61437594</ns1:transid> 
     <ns1:descriptionerr>BLAH.</ns1:descriptionerr> 
    </ns1:responseINFOWL> 
</ns1:opINFOWLResponse> 

लेकिन unmarshal नहीं कर सकते हैं:

<?xml version="1.0" encoding="UTF-8"?> 
<ns1:opINFOWLResponse xmlns:ns1="http://www.acme.com/ws" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <ns1:responseINFOWL xsi:type="ns1:responseINFOWL"> 
     <result>6003</result> 
     <ndserr /> 
     <transid>61437594</transid> 
     <descriptionerr>BLAH.</descriptionerr> 
    </ns1:responseINFOWL> 
</ns1:opINFOWLResponse> 

इसका मतलब यह है कि आपके JAXB मैपिंग में नाम स्थान योग्यता गलत है। निम्नलिखित मदद मिल सकती है:

आप वर्ग है कि XML के इस भाग को नक्शे, और package-info वर्ग पोस्ट कर सकता है अगर वहाँ एक है, तो मैं मदद कर सकते हैं मैपिंग संशोधित करें।

2

मैंने हाल ही में आपके सामने आने वाली एक ही समस्या में भाग लिया, और यह इस तथ्य से नीचे आ गया कि जिस सेवा से मैं संपर्क कर रहा था वह उसके डब्लूएसडीएल के विज्ञापन से कुछ अलग लौट रहा था। इस सेवा ने अपाचे एक्सिस (1.4) के पुराने संस्करण का उपयोग व्यवहार के साथ किया जो वर्तमान जेएक्स-डब्ल्यूएस कार्यान्वयन के साथ संघर्ष करता है।

विशेष रूप से, वास्तविक प्रतिक्रिया शरीर सामग्री पर नामस्थान जेएक्स-डब्ल्यूएस की wsimport उपयोगिता द्वारा उत्पन्न क्लाइंट कोड द्वारा अपेक्षित नहीं था।

<?xml version="1.0" encoding="utf-8"?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <soapenv:Body> 
     <serviceResponse xmlns="http://foo.com"> 
      <messageReturn> 
       <messageId>12345</messageId> 
       <status>Ok</status> 
      </messageReturn> 
     </serviceResponse> 
    </soapenv:Body> 
</soapenv:Envelope> 

क्या वास्तव में वापस आ रहा था के विपरीत, ग्राहक wsimport द्वारा उत्पन्न स्टब्स की तरह कुछ उम्मीद कर रहे थे: उदाहरण के लिए, वास्तविक प्रतिक्रिया कुछ इस तरह, serviceResponse और नाम स्थान "http://foo.com" में अपने सभी बच्चों के साथ देखा नेमस्पेस "http://foo.com" में सेवा रिस्पॉन्स तत्व के साथ नीचे प्रतिक्रिया, और अज्ञात नाम संदेश में निहित बाल संदेश रीटर्न तत्व।

<?xml version="1.0" encoding="utf-8"?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <soapenv:Body> 
     <n1:serviceResponse xmlns:n1="http://foo.com"> 
      <messageReturn> 
       <messageId>12345</messageId> 
       <status>Ok</status> 
      </messageReturn> 
     </n1:serviceResponse> 
    </soapenv:Body> 
</soapenv:Envelope> 

जब से मैं सेवा मैं लेने गया था परिवर्तित नहीं कर सके, मैं बजाय लिखा एक नया डबल्यूएसडीएल अपने आप का उपयोग किया जाता है एक लिपटे डॉक-शाब्दिक स्पष्ट रूप से प्रतिक्रिया की उम्मीद संरचना को नियंत्रित करने के बंधन (और अनुरोध ज़ाहिर है,)। IBM Developerworks.

डबल्यूएसडीएल मैं कुछ इस तरह देखा बनाया से अधिक डबल्यूएसडीएल बंधन प्रकार पर एक बहुत अच्छी लेख है:

<?xml version="1.0" encoding="UTF-8"?> 

<wsdl:definitions targetNamespace="http://foo.com" 
        xmlns:tns="http://foo.com" 
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
        xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 

    <!-- Define the XML types we need to send and receive (used by the message definitions below) --> 
    <wsdl:types> 
     <schema targetNamespace="http://foo.com" xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> 

      <!-- Reusable types --> 
      <complexType name="ResponseType"> 
       <sequence> 
        <element name="messageId" nillable="true" type="xsd:string" /> 
        <element name="status" nillable="true" type="xsd:string" /> 
       </sequence> 
      </complexType> 

      <complexType name="InputType"> 
       <sequence> 
        <element name="firstName" nillable="true" type="xsd:string" /> 
        <element name="lastName" nillable="true" type="xsd:string" /> 
        <element name="command" nillable="true" type="xsd:string" /> 
       </sequence> 
      </complexType> 


      <!-- Specific input/output elements used in wsdl:message definitions --> 
      <element name="serviceResponse"> 
       <complexType> 
        <sequence> 
         <element name="messageReturn" type="tns:ResponseType" /> 
        </sequence> 
       </complexType> 
      </element> 

      <element name="serviceRequest"> 
       <complexType> 
        <sequence> 
         <element name="message" type="tns:InputType" /> 
        </sequence> 
       </complexType> 
      </element> 
     </schema> 
    </wsdl:types> 


    <!-- Define the WSDL messages we send/receive (used by the port definition below) --> 
    <wsdl:message name="serviceResponseMessage"> 
     <wsdl:part name="part1Name" element="tns:serviceResponse" /> 
    </wsdl:message> 

    <wsdl:message name="serviceRequestMessage"> 
     <wsdl:part name="part1name" element="tns:serviceRequest" /> 
    </wsdl:message> 


    <!-- Define the WSDL port (used by the binding definition below) --> 
    <wsdl:portType name="ServicePort"> 
     <wsdl:operation name="serviceOperation"> 
      <wsdl:input message="tns:serviceRequestMessage" /> 
      <wsdl:output message="tns:serviceResponseMessage" /> 
     </wsdl:operation> 
    </wsdl:portType> 


    <!-- Define the WSDL binding of the port (used by the service definition below) --> 
    <wsdl:binding name="ServiceSoapBinding" type="tns:ServicePort"> 
     <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> 

     <wsdl:operation name="serviceOperation"> 
      <wsdlsoap:operation soapAction="" /> 

      <wsdl:input> 
       <wsdlsoap:body use="literal" /> 
      </wsdl:input> 

      <wsdl:output> 
       <wsdlsoap:body use="literal" /> 
      </wsdl:output> 
     </wsdl:operation> 
    </wsdl:binding> 


    <!-- Finally, define the actual WSDL service! --> 
    <wsdl:service name="UserCommandService"> 
     <wsdl:port binding="tns:ServiceSoapBinding" name="ServicePort"> 
      <!-- This address is just a placeholder, since the actual target URL will be specified at runtime --> 
      <wsdlsoap:address location="http://localhost:8080/blah" /> 
     </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

कस्टम डबल्यूएसडीएल के साथ, मैं wsimport उपयोग करने के लिए ग्राहक स्टब्स कि पूरी तरह से काम उत्पन्न करने में सक्षम था सेवा के साथ। साथ ही, लपेटा हुआ दस्तावेज़-शाब्दिक दृष्टिकोण के साथ, मैं अनुरोध/प्रतिक्रिया की अपेक्षित संरचना और नामस्थान को पूरी तरह से नियंत्रित करता हूं, इसलिए यदि आवश्यक हो तो मैं उस XML में एकाधिक नामस्थान लागू कर सकता हूं।

आनंद लें ...

संबंधित मुद्दे