首页 > Web开发 > 详细

通过wcf的webservice访问服务器

时间:2014-07-14 21:06:19      阅读:456      评论:0      收藏:0      [点我收藏+]

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访问服务器,布布扣,bubuko.com

通过wcf的webservice访问服务器

原文:http://www.cnblogs.com/llh0204/p/3842669.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!