首页 > 代码库 > WSDL接口调用
WSDL接口调用
import java.io.IOException;import java.util.Iterator;import java.util.Map;import org.ksoap2.SoapEnvelope;import org.ksoap2.serialization.MarshalBase64;import org.ksoap2.serialization.SoapObject;import org.ksoap2.serialization.SoapSerializationEnvelope;import org.ksoap2.transport.HttpTransportSE;import org.xmlpull.v1.XmlPullParserException;public class WebServiceAction { public static SoapObject getSoapObject(String Wsdl, String methodName, Map<String, Object> inputmap, String NAMESPACE) { SoapObject reqSoapObject = new SoapObject(NAMESPACE, methodName); //遍历input Iterator iter = inputmap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); Object key = entry.getKey(); Object val = entry.getValue(); reqSoapObject.addProperty((String) key, val); } SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.bodyOut = reqSoapObject; envelope.dotNet = false; envelope.encodingStyle="UTF-8"; (new MarshalBase64()).register(envelope); HttpTransportSE transport = new HttpTransportSE(Wsdl, 20000); transport.debug = true; try { transport.call(NAMESPACE + methodName, envelope); if (envelope.getResponse() != null) { SoapObject get_soap = (SoapObject) envelope.getResponse(); return get_soap; } } catch (IOException e) { e.printStackTrace(); } catch (XmlPullParserException e) { e.printStackTrace(); } return null; } public static Object getSoapObjectResponse(String Wsdl, String methodName, Map<String, Object> inputmap, String NAMESPACE) { SoapObject reqSoapObject = new SoapObject(NAMESPACE, methodName); // 遍历inputmap Iterator iter = inputmap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); Object key = entry.getKey(); Object val = entry.getValue(); reqSoapObject.addProperty((String) key, val); } SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.bodyOut = reqSoapObject; envelope.dotNet = false; (new MarshalBase64()).register(envelope); HttpTransportSE transport = new HttpTransportSE(Wsdl, 30000); transport.debug = true; try { transport.call(NAMESPACE + methodName, envelope); if (envelope.getResponse() != null) { return envelope.getResponse(); } } catch (IOException e) { e.printStackTrace(); } catch (XmlPullParserException e) { e.printStackTrace(); } return null; } }
另一个方法是拼接soap数据
WSDL接口调用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。