Java-JAX-WS和SharePoint用户组Web服务
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Java-JAX-WS和SharePoint用户组Web服务,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3826字,纯文字阅读大概需要6分钟。
内容图文
![Java-JAX-WS和SharePoint用户组Web服务](/upload/InfoBanner/zyjiaocheng/652/7e26fda4230a4eab97a56cd9e345c9b5.jpg)
我有一个小应用程序,可以查询我们的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
D.< GetUserCollectionFromGroupResult>的WSDL模式定义.包括< xs:any> ;:
<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上找到.
内容总结
以上是互联网集市为您收集整理的Java-JAX-WS和SharePoint用户组Web服务全部内容,希望文章能够帮你解决Java-JAX-WS和SharePoint用户组Web服务所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。