ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码
当前位置:首页 >> 网页制作 >> web前端 >> webService客户端传xml请求 直接main方法运行

webService客户端传xml请求 直接main方法运行

来源:网络整理     时间:2018-06-28     关键词:

本篇文章主要介绍了" webService客户端传xml请求 直接main方法运行",主要涉及到方面的内容,对于web前端感兴趣的同学可以参考一下: import java.io.File;import java.io.FileInputStream;import java.io.IOException;im...

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.dom4j.Document;
import org.dom4j.io.SAXReader;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpResponseException;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;


public class WebServiceUtils {
	// public static final String WebServiceNamespace
	// ="http://WebXml.com.cn/";//http://webservice.keResource.fai.sysware.com";//地址
	// public static final String WebAddress =
	// "http://192.168.145.110:80/sysware/services/KeResourceWS?wsdl";//地址
	public static Object callWebservice(String WebServiceNamespace, String WebServiceUrl, String method,
			String[] params, Object[] values) throws HttpResponseException, IOException, XmlPullParserException {
		Object result = null;

		SoapObject rpc = new SoapObject(WebServiceNamespace, method);
		if (params != null) {
			for (int i = 0; i < params.length; i++)
				rpc.addProperty(params[i], values[i]);
		}
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.bodyOut = rpc;
		envelope.dotNet = true;
		envelope.setOutputSoapObject(rpc);

		HttpTransportSE ht = new HttpTransportSE(WebServiceUrl, 1000);
		ht.debug = false;

		String SOAP_ACTION = WebServiceNamespace + method;
		ht.call(SOAP_ACTION, envelope);
		result = envelope.getResponse();
		if (result != null) {
			return result;
		} else {
			return null;
		}

	}
	public static void main(String[] args) {
		String nameSp = "http://www.teamcenter.com/webservice";
		String webUrl = "http://tshserver:8080/ws";
		String method = "createBOMRequest";
		String xml = getXmlString("C:\\test1.xml");
		String para = "xmlString";
		try {
			Object resultObject = callWebservice(nameSp,webUrl,method,new String[]{para},new Object[]{xml});
			SoapPrimitive result = (SoapPrimitive) resultObject;
			System.out.println("result=====" + result);
		} catch (IOException | XmlPullParserException e) {
			e.printStackTrace();
		}
	}
	public static String getXmlString(String path) {
		String xml="";
		try {
			FileInputStream fis = new FileInputStream(new File(path));
			SAXReader reader = new SAXReader();
			Document document = reader.read(fis);
			xml= document.asXML();  
		} catch (Exception e) {
			e.printStackTrace();
		}
		return xml;
	}

}

以上就介绍了 webService客户端传xml请求 直接main方法运行,包括了方面的内容,希望对web前端有兴趣的朋友有所帮助。

本文网址链接:http://www.codes51.com/article/detail_4572414.html

相关图片

相关文章