码迷,mamicode.com
首页 > Web开发 > 详细

通过wcf的webservice访问服务器

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

标签:http   java   os   数据   for   io   

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   java   os   数据   for   io   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!