LoadRunner中使用java协议发送webservice请求

需要引入的jar包:

jdom.jar、wsdl4j-1.6.1.jar、xfire-all-1.2.6.jar、XmlSchema-1.1.jar

 

代码:

/*
 * LoadRunner Java script. (Build: _build_number_)
 * 
 * Script Description: 
 *                     
 */

import lrapi.lr;
import java.util.*;
import java.lang.*;
import org.codehaus.xfire.client.Client;
import java.net.URL;
import java.net.MalformedURLException;

public class Actions
{
	public int init() throws Throwable {
         
	    return 0;
	}//end of init


	public int action() throws Throwable {
          Client client = null;

    try {

      client = new Client(new URL("http://127.0.0.1:8080/xx/xx/xx?wsdl"));

      Object[] result1 = client.invoke("xx", new Object[]{"{\"xx\":\"123\",\"xx\":\"1\", \"xx\":{\"xx\":\"12345678\", \"xx\":\"12345678\", \"xx\":\"123456\", \"xx\":\"321\",\"xx\":\"123456\"} }"});

      System.out.println(result1[0]);

    } catch (MalformedURLException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }


		return 0;
	}//end of action


	public int end() throws Throwable {
		return 0;
	}//end of end
}

 

你可能感兴趣的:(java,webservice,loadrunner)