各位大大:我用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 略....
}

解决方案 »

  1.   

    哎!只好用最土的方式自己写post,自己获取数据报文的方式了,就是解析xml好麻烦啊
      

  2.   

    别人写的基础类HttpURLConnection类,分享下。package test;import java.io.BufferedReader;
    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();
    }
    }
    }