编程语言
首页 > 编程语言> > Java-JAX-WS和SharePoint用户组Web服务

Java-JAX-WS和SharePoint用户组Web服务

作者:互联网

我有一个小应用程序,可以查询我们的SharePoint服务器的Web服务界面以获取组中所有用户的列表.
我可以看到原始的HTTP响应将与列出的所有用户一起返回,但是JAX-WS响应对象(在NetBeans 6.9下创建)仅包含一个空白的Group Name String值. HTTP响应中没有跟踪所有用户名.

有人知道为什么JAX-WS无法正确读取SOAP响应吗?

WSDL已经发布很久了,但是可以从各个位置(包括此站点)进行广泛访问:
http://www.hezser.de/_vti_bin/UserGroup.asmx?wsdl

这是原始HTTP响应的开始:

---[HTTP response - http://{server}/_vti_bin/usergroup.asmx - 200]---
null: HTTP/1.1 200 OK
Cache-control: private, max-age=0
Content-type: text/xml; charset=utf-8
Content-length: 136738
X-powered-by: ASP.NET
Server: Microsoft-IIS/6.0
Date: Wed, 22 Sep 2010 20:53:12 GMT
X-aspnet-version: 2.0.50727
Set-cookie: WSS_KeepSessionAuthenticated=80; path=/
Microsoftsharepointteamservices: 12.0.0.6303
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetUserCollectionFromGroupResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/"><GetUserCollectionFromGroupResult><GetUserCollectionFromGroup><Users><User ID="201" Sid="S-1-5-21-1545385408-2720673749-3828181483-1245" ....

解决方法:

您需要在生成存根之前手动编辑UserGroup.wsdl.您需要将processContents =’skip’添加到< s:any>定义响应的标签.

<s:element name="GetUserCollectionFromGroupResponse">
 <s:complexType>
  <s:sequence>
    <s:element minOccurs="0" maxOccurs="1" name="GetUserCollectionFromGroupResult">
      <s:complexType mixed="true">
        <s:sequence>
          <!-- Added the "processContents" attribute below -->
          <s:any processContents='skip' />    
        </s:sequence>
      </s:complexType>
    </s:element>
  </s:sequence>
 </s:complexType>
</s:element>

然后,当处理响应时,JAXB将把子元素作为DOM元素返回:

UserGroup service = new UserGroup();
UserGroupSoap port = service.getUserGroupSoap();

GetUserCollectionFromGroupResult usersCollection = port.getUserCollectionFromGroup(Settings.usersGroup);
List<Object> content = usersCollection.getContent();
org.w3c.dom.Element usersElement = (org.w3c.dom.Element) content.get(0);

为什么这样做

该问题是由多种情况引起的:

A. Web服务返回的响应包含< GetUserCollectionFromGroup>.标签:

<GetUserCollectionFromGroupResult>
    <GetUserCollectionFromGroup>
       <Users>
          <User ID="4" Name="User1_Display_Name" />
          <User ID="5" Name="User2_Display_Name" />
       </Users>
    </GetUserCollectionFromGroup>
</GetUserCollectionFromGroupResult>

B.嵌入WSDL的模式定义了< GetUserCollectionFromGroup>.包含一个孩子,< groupName> (这是用于发出请求的元素):

<s:element name="GetUserCollectionFromGroup">
  <s:complexType>
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="groupName" type="s:string"/>
    </s:sequence>
  </s:complexType>
</s:element>

C. JAXB支持< xs:any>的processContents属性. (请参阅Mapping of <xs:any />).当processContents =’strict’时,JAXB尝试根据子元素所属的名称空间匹配(并编组)子元素.

D.< GetUserCollectionFromGroupResult>的WSDL模式定义.包括< xs:any&gt ;:

<s:element name="GetUserCollectionFromGroupResponse">
 <s:complexType>
  <s:sequence>
    <s:element minOccurs="0" maxOccurs="1" name="GetUserCollectionFromGroupResult">
      <s:complexType mixed="true">
        <s:sequence>
          <s:any/>
        </s:sequence>
      </s:complexType>
    </s:element>
  </s:sequence>
 </s:complexType>
</s:element>

E.当省略processContents时,默认值为strict.

因此,当JAX-WS / JAXB处理来自Web服务的结果时,它将尝试编组< GetUserCollectionFromGroupResult>的子级.使用架构.子级在响应中显示为与请求属于同一名称空间.当< GetUserCollectionFromGroup>元素被处理后,将被编组为< GetUserCollectionFromGroup>请求中使用的同一类的实例.元件.因此,有效地阻止了您到达< Users>用户.元素.

我已经搜索了高低,我唯一能找到的解决方案是以太(a)按照此答案开头所述的那样编辑WSDL,或(b)编辑生成的存根.不理想,但在这种情况下是不可避免的.

有关< xs:any>的更多信息.模式元素(和processContents属性)可以在MSDN here上找到.

标签:jax-ws,web-services,java,sharepoint
来源: https://codeday.me/bug/20191209/2096528.html