SOAP服务端操作


import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

import org.apache.log4j.Logger;

@WebService
public class ParamService {

	private static Logger logger = Logger.getLogger(BatchAuthService.class);


	/**
	 * 
	 * @param name
	 * @return
	 */
	@WebMethod
	@WebResult(name = "paramReturn")
	public String batchAuth(@WebParam(name = "pa1") String pa1, @WebParam(name = "pa2") String pa2, @WebParam(name = "pa3") String pa3) {
				
		
		
		
		return pa1;
	}

}

Endpoint.publish("http://12.12.12.12/services/getparam", new ParamService());

String wsdl = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl";

 StringBuffer sb = new StringBuffer("");
 sb.append("");

URL url = new URL(wsdl);                                                                           
 HttpURLConnection conn = (HttpURLConnection) url.openConnection();                                 
                                                                                                                     
   conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8"); 
                  conn.setRequestMethod("POST");                                                                     
                  conn.setUseCaches(false);                                                                          
                  conn.setDoInput(true);                                                                             
                  conn.setDoOutput(true);                                                                            
                  conn.setConnectTimeout(timeout);                                                                   
                  conn.setReadTimeout(timeout);                                                                      
                                                                                                                     
                  DataOutputStream dos = new DataOutputStream(conn.getOutputStream());                               
                  dos.write(sb.toString().getBytes("utf-8"));                                                        
                  dos.flush();                                                                                       
                                                                                                                                                                         
                  BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
                  String line = null;                                                                                
                  StringBuffer strBuf = new StringBuffer();                                                          
                  while ((line = reader.readLine()) != null) {                                                       
                      strBuf.append(line);                                                                           
                  }                                                                                                  
                  dos.close();                                                                                       
                  reader.close();                                                                                    
                                                                                                                     
                  System.out.println(strBuf.toString());

你可能感兴趣的:(java)