2012-01-30 67 views
0

我調用了文檔樣式的SOAP Web服務。它與SOAP UI協同工作,但我在嘗試調用它時遇到錯誤。從Web服務調用中獲取'元素未聲明'響應

下面是我從服務器獲取錯誤:

<SubmitRequestDocResponse xmlns="http://tripauthority.com/hotel"> 
    <SubmitRequestDocResult> 
    <ArnResponse xmlns:ns2="http://tripauthority.com/hotel" xmlns=""> 
     <Error> 
     <Message> 
       Request is not valid. Details: The 
       'http://tripauthority.com/hotel:ArnRequest' 
       element is not declared. 
     </Message> 
     </Error> 
    </ArnResponse> 
    </SubmitRequestDocResult> 
</SubmitRequestDocResponse> 

代碼調用它看起來像:

ARequestDoc requestDoc = objectFactory.createSubmitRequestDocARequestDoc(); 
ArnRequest request = requestFactory.createArnRequest(); 
requestDoc.getContent().add(request); 
SubmitRequestDocResult response = 
    soap.submitRequestDoc("id", "username", "password", requestDoc); 

和所使用的類被組織並註明:

package com.company.server.ws:

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "", propOrder = { 
    "siteID", 
    "aUserName", 
    "aPassword", 
    "aRequestDoc" 
}) 
@XmlRootElement(name = "SubmitRequestDoc") 
@XmlSeeAlso(ArnRequest.class) 
public class SubmitRequestDoc { // Stuff... } 


@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "", propOrder = { 
    "content" 
}) 
public static class ARequestDoc { // Stuff ... } 

包com.company.server.ws.request:

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "", propOrder = { 
    "availability", 
    "rateDetails", 
    "reservation", 
    "cancellation" 
}) 
@XmlRootElement(name = "ArnRequest") 
public class ArnRequest { // Stuff ... } 

此外,com.company.server.ws具有以下package-info.java

@javax.xml.bind.annotation.XmlSchema(
     namespace = "http://tripauthority.com/hotel", 
     elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) 
package com.company.server.ws; 

此外,爲什麼它的價值,這裏的WSDLXSD for the Request

有沒有人有任何想法我能做些什麼來讓這個消息發送正確?我可以使用SOAP UI發送硬編碼的字符串請求,它工作得很好。

感謝

編輯 對於它的價值,我的猜測,到目前爲止一直是它可能經歷,如果我能以某種方式發送ArnRequest部分沒有任何命名空間中聲明,如果有任何的方式來做到這一點,但這只是一個猜測,任何見解都是值得讚賞的。

回答

0

想通了一種方法使其工作。

我添加了另一個package-info.java文件com.company.server.ws.request這基本宣告沒有命名爲ArnRequest對象,像這樣下:

@javax.xml.bind.annotation.XmlSchema(elementFormDefault = 
      javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) 
package com.company.server.ws.request; 

如果我理解正確的這個,這是告訴序列化程序爲ArnRequest obect設置'no'命名空間,並通過將默認設置爲UNQUALIFIED來關閉驗證。

我不確定這是做什麼,但它現在肯定有效,所以更多的見解將不勝感激。