通过wcf的webservice访问服务器

package com.factory.webserviceutils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

public class WebServiceUtils {
// 命名空间
public static final String SERVICE_NAMESPACE = "http://tempuri.org/";

public static final String SERVICE_URL = "http://192.168.1.156/ProduceManageSystemWebService/";
/*
* 通过wcf返回服务器数据
* **/
public static List<String> getUser() {
String methodName = "GetManagement";

HttpTransportSE ht = new HttpTransportSE(SERVICE_URL);
try {
ht.debug = true;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
SoapObject soapObject = new SoapObject(SERVICE_NAMESPACE,
methodName);
envelope.bodyOut = soapObject;
envelope.dotNet = true;

ht.call(SERVICE_NAMESPACE + methodName, envelope);
if (envelope.getResponse() != null) {
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject detail = (SoapObject) result.getProperty(methodName
+ "Result");
return parseUser(detail);

/* String object = result.getProperty(0).toString();
System.out.println("Helloservice::Object" + object); return
object;
*/

}
} catch (SoapFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}

 

public static List<String> parseUser(SoapObject detail) {
List<String> list = new ArrayList<String>();
for (int i = 0; i < detail.getPropertyCount(); i++) {
list.add(detail.getProperty(i).toString().split("=")[1].split(";")[0]);
}
System.out.println("list.size()" + list.size());
for(int i=0;i<list.size();i++)

{
System.out.println("list.get(i)"+list.get(i));
}
return list;

}
}

通过wcf的webservice访问服务器,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。