的SharePoint Web服务JAX-WS命名空间冲突(SharePoint Web Servi

2019-09-27 04:24发布

我试图使用SharePoint Web服务来检索名单的变化,但似乎有什么之间的JAX-WS客户产生什么SharePoint将接受一个命名空间冲突。 下面是由JAX-WS生成的XML。

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <GetListItemChanges xmlns="http://schemas.microsoft.com/sharepoint/soap/">
      <listName>Documents</listName>
      <viewFields>
        <FieldRef Name="Modified"/>
        <FieldRef Name="_CheckinComment"/>
        <FieldRef Name="Title"/>
        <FieldRef Name="Created"/>
      </viewFields>
      <since>1970-01-01T00:00:00</since>
      <contains/>
    </GetListItemChanges>
  </S:Body>
</S:Envelope>

我需要从GetListItemChanges除去的xmlns =“http://schemas.microsoft.com/sharepoint/soap/”。 我曾尝试以下(和各种排列它们),但变化似乎被忽略。 该XMLNS调试时被删除,但输出XML不会改变。

public class SharePointSoapHandler implements SOAPHandler<SOAPMessageContext> {
  ...
 @Override
  public boolean handleMessage(SOAPMessageContext p_soapMessageContext) {
    try {
      SOAPMessage l_soapMessage = p_soapMessageContext.getMessage();
      l_soapMessage.getSOAPBody().getFirstChild().getAttributes().removeNamedItem("xmlns");
      l_soapMessage.saveChanges();
      ByteArrayOutputStream l_outputStream = new ByteArrayOutputStream();
      l_soapMessage.writeTo(l_outputStream);
      m_logger.info(new String(l_outputStream.toByteArray()));
    } catch (Exception ex) {
      m_logger.error("Soap exception modifying xml for request", ex);
    }
    return true;
  }
}

我缺少的东西吗? 有没有更好的方式来做到这一点还是我需要手动生成的XML?

编辑:用肥皂UI有效的SOAP请求。 JAX-WS丢弃第二前缀和移动xmlns属性。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.microsoft.com/sharepoint/soap/">
   <soapenv:Header/>
   <soapenv:Body>
      <soap:GetListItemChanges>
         <!--Optional:-->
         <soap:listName>Shared Documents</soap:listName>
         ...
         <soap:since>2012-02-15T00:00:00</soap:since>

      </soap:GetListItemChanges>
   </soapenv:Body>
</soapenv:Envelope>

Answer 1:

看到改变与JAXWS生成的默认XML命名空间前缀使用的处理程序拦截肥皂和根据需要修改它; 还用于调试发送过来的电线肥皂作为其一种有用的技术。

您还可以设置在SOAP头,像这样的命名空间声明:

SOAPMessage request = factory.createMessage();
SOAPEnvelope envelope = request.getSOAPPart().getEnvelope();
envelope.addNamespaceDeclaration("uri", "uri:foo.bar.com");
request.saveChanges();

然后创建一个这样的命名空间前缀的元素:

SOAPBody body = request.getSOAPBody();
SOAPElement ping = body.addChildElement("foo", "uri");

没有首先在报头中设置的声明,添加具有该前缀的元件将失败。

处事方式似乎规避具有空间声明挂体节点,这是打破什么,我试图做的。

下面是我用来验证这个作品在我的JUnit测试:

public void testPing() throws Exception {

String endpoint = "http://www.foo.bar/ws/someWebservice";
QName port = new QName(endpoint, "uri");
QName serviceName = new QName(endpoint, "someWebserviceMethod");

Service service = Service.create(serviceName);
service.setHandlerResolver(new MyHandlerResolver());
service.addPort(port, SOAPBinding.SOAP11HTTP_BINDING, endpoint);

Dispatch<SOAPMessage> dispatch = service.createDispatch(port, SOAPMessage.class, Service.Mode.MESSAGE);
MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
SOAPMessage request = factory.createMessage();

SOAPEnvelope envelope = request.getSOAPPart().getEnvelope();
envelope.addNamespaceDeclaration("uri", "uri:bar.foo");
request.saveChanges();

SOAPBody body = request.getSOAPBody();

SOAPElement element = body.addChildElement("someRequestElement", "uri");
SOAPElement child = ping.addChildElement("someRequestChild");

SOAPElement text_node = child.addChildElement("someTextNode");
messageType.addTextNode("test text");

request.saveChanges();

System.out.println();
request.writeTo(System.out);
System.out.println();

Object o = dispatch.invoke(request);

System.out.println("ret: " + o.toString());

assertNotNull( o );

}



文章来源: SharePoint Web Services jax-ws namespace conflict