各位大大:我用java访问.net的web service, 设置返回对象的时候就是不行。 下面是部分代码。方法:GetUserList回复就散分哦wsdl:
- <s:element name="GetUserListResponse">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetUserListResult" type="tns:ArrayOfT_User" />
</s:sequence>
</s:complexType>
</s:element>
- <s:complexType name="ArrayOfT_User">
- <s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="t_User" nillable="true" type="tns:t_User" />
</s:sequence>
</s:complexType>
- <s:complexType name="t_User">
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="UserID" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="UserName" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="LoginName" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="IsEnabled" nillable="true" type="s:boolean" />
<s:element minOccurs="1" maxOccurs="1" name="LastUpdate" nillable="true" type="s:dateTime" />
<s:element minOccurs="1" maxOccurs="1" name="LastLogin" nillable="true" type="s:dateTime" />
<s:element minOccurs="1" maxOccurs="1" name="CreateTime" nillable="true" type="s:dateTime" />
<s:element minOccurs="0" maxOccurs="1" name="DepMemo" type="s:string" />
</s:sequence>
</s:complexType>
java设置返回值的代码:call.addParameter(new QName("http://sso.aaa.org/", "OperatorID"), XMLType.SOAP_STRING, ParameterMode.IN); call.setReturnType(new QName("http://sso.aaa.org/","t_User"), t_User[].class
//注册映射关系
QName XljgInfo = new QName("http://sso.aaa.org/", "t_User"); call.registerTypeMapping(t_User.class, XljgInfo,
new BeanSerializerFactory(t_User.class, XljgInfo),
new BeanDeserializerFactory(t_User.class, XljgInfo));
t_User[] ret = (t_User[]) call.invoke(new Object[] {"9"});
上面的t_User类:
public class t_User { private String UserID ;
private String UserName ;
private String LoginName ;
private String Password ;
private Boolean IsEnabled ;
private DateTime LastUpdate ;
private DateTime LastLogin ;
private DateTime CreateTime ;
private String DepMemo ;
//get set 略....
}
- <s:element name="GetUserListResponse">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetUserListResult" type="tns:ArrayOfT_User" />
</s:sequence>
</s:complexType>
</s:element>
- <s:complexType name="ArrayOfT_User">
- <s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="t_User" nillable="true" type="tns:t_User" />
</s:sequence>
</s:complexType>
- <s:complexType name="t_User">
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="UserID" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="UserName" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="LoginName" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="IsEnabled" nillable="true" type="s:boolean" />
<s:element minOccurs="1" maxOccurs="1" name="LastUpdate" nillable="true" type="s:dateTime" />
<s:element minOccurs="1" maxOccurs="1" name="LastLogin" nillable="true" type="s:dateTime" />
<s:element minOccurs="1" maxOccurs="1" name="CreateTime" nillable="true" type="s:dateTime" />
<s:element minOccurs="0" maxOccurs="1" name="DepMemo" type="s:string" />
</s:sequence>
</s:complexType>
java设置返回值的代码:call.addParameter(new QName("http://sso.aaa.org/", "OperatorID"), XMLType.SOAP_STRING, ParameterMode.IN); call.setReturnType(new QName("http://sso.aaa.org/","t_User"), t_User[].class
//注册映射关系
QName XljgInfo = new QName("http://sso.aaa.org/", "t_User"); call.registerTypeMapping(t_User.class, XljgInfo,
new BeanSerializerFactory(t_User.class, XljgInfo),
new BeanDeserializerFactory(t_User.class, XljgInfo));
t_User[] ret = (t_User[]) call.invoke(new Object[] {"9"});
上面的t_User类:
public class t_User { private String UserID ;
private String UserName ;
private String LoginName ;
private String Password ;
private Boolean IsEnabled ;
private DateTime LastUpdate ;
private DateTime LastLogin ;
private DateTime CreateTime ;
private String DepMemo ;
//get set 略....
}
解决方案 »
- hibernate4 spring 3.1 struts2 dbcp连接错误
- 多线程问题
- 【求救啊】也许较为简单的问题,但搞不出来
- 关于STRUTS的一个应用问题
- java里如何保存一个int数组到xml中
- 急!!在线等!!用struts的DownloadAction类做了一个文件下载的例子,怎么实现文件的换名保存和换路径保存,进来回复就有分可加。各位帮
- tomcat与ant的环境配置问题??????!!!!!
- 泣问:能否从远端获得一个自定义对象,在本地调用这个对象的方法?
- 好心的哥们们:我刚配置好我的apache2+tomcate5,但运行jsp出现HTTP Status 500 错误,快来帮忙(在线等)
- strusts
- 树形结构
- ssi整合问题 启动报错
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;public class TestWS2 {
public static void main(String[] args) {
try {
String urlString = "http://localhost:8090/ws/DeliveryList.asmx";
String xmlFile = "d:\\A.XML";//这个是请求的SOAP格式内容,访问上面的接口就能看到,这里就不提供了
String soapActionString = "http://www.k78.cn/GetDeliveryListByStatus";
File fileToSend = new File(xmlFile);
byte[] buf = new byte[(int) fileToSend.length()];
new FileInputStream(xmlFile).read(buf); URL url = new URL(urlString);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Length", String.valueOf(buf.length));
httpConn.setRequestProperty("Content-Type","text/xml; charset=utf-8");
httpConn.setRequestProperty("SOAPAction", soapActionString);
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
OutputStream out = httpConn.getOutputStream();
out.write(buf);
out.close(); InputStreamReader isr = new InputStreamReader(httpConn.getInputStream(), "utf-8");
BufferedReader in = new BufferedReader(isr); String inputLine;
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D:\\result.xml")));
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine.replaceAll("><", ">\n<"));
bw.write(inputLine);
bw.newLine();
}
bw.close();
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}