从Web服务调用获取“元素未声明”响应

时间:2012-01-30 13:51:26

标签: java soap jaxb jax-ws

我调用了文档样式的SOAP Web服务。它适用于SOAP UI,但是我试图以programaticaly方式调用它时出错。

以下是我从服务器获取的错误:

<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);

使用的类是有组织和注释的:

  

包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部分而没有声明任何名称空间,如果有任何方法可以做到这一点,它可能会通过,但是这只是一个猜测,任何见解都表示赞赏。

1 个答案:

答案 0 :(得分:0)

想出一种让它发挥作用的方法。

我在 com.company.server.ws.request 下添加了另一个package-info.java文件,该文件基本上为ArnRequest对象声明了 no 名称空间,像这样:

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

如果我理解正确,它告诉序列化程序为ArnRequest obect设置'no'命名空间,并通过将表单default设置为UNQUALIFIED来关闭验证。

我不确定这到底是做什么的,但它现在肯定有效,所以我们将不胜感激。

相关问题