|
最近做webservice性能测试,系统是用C#开发,支持后台线程,通过事件委托实现了webservice调用的异步处理。
性能测试需求,在一个Vuser中,将调用webservice的web_service_call函数和处理web Service返回结果分开,能够让多个webservice调用并发进行。而不是串行的。
我的现在的代码如下,能够进一步优化吗? 此代码解决了webservice返回值为xml文件的问题,有需要的可以看一下。- action()
- {
- int Num ,i;
- char po[64],pt[64],vt[64],ptime[64];
- typedef long time_t;
- time_t t;
- lr_message ("Time in seconds since 1/1/70: %ld\n", time(&t));
- lr_save_int((time(&t)-604800),"begintime");
- lr_save_int(time(&t),"endtime");
- web_service_call( "StepName=getFisheriesSchema_101",
- "SOAPMethod=DataService|DataServiceSoap|getFisheriesSchema",
- "ResponseParam=response",
- "Service=DataService",
- "ExpectedResponse=SoapResult",
- "Snapshot=t1377561681.inf",
- BEGIN_ARGUMENTS,
- "userName=IDP",
- "password=IDP",
- "reqSn=1",
- "beginTime={begintime}",
- "endTime={endtime}",
- END_ARGUMENTS,
- BEGIN_RESULT,
- "getFisheriesSchemaResult=Param_getFisheriesSchemaResult",
- END_RESULT,
- LAST);
- lr_output_message(lr_eval_string("{Param_getFisheriesSchemaResult}"));
- lr_convert_string_encoding(lr_eval_string("{Param_getFisheriesSchemaResult}"),LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"str");
- Num = lr_xml_get_values("XML={str}",
- "valueParam=ProdOrg",
- "Query=/getFisheriesSchemaResult/ProductSchema/ProdOrg",
- "SelectAll=yes",
- LAST);
- lr_xml_get_values("XML={str}",
- "valueParam=PostTime",
- "Query=/getFisheriesSchemaResult/ProductSchema/Post_Time",
- "SelectAll=yes",
- LAST);
- lr_xml_get_values("XML={str}",
- "valueParam=VType",
- "Query=/getFisheriesSchemaResult/ProductSchema/VType",
- "SelectAll=yes",
- LAST);
- lr_xml_get_values("XML={str}",
- "valueParam=ProdType",
- "Query=/getFisheriesSchemaResult/ProductSchema/ProdType",
- "SelectAll=yes",
- LAST);
- for ( i = 0; i < Num; i++) { /* Print multiple values of OutputParam */
- sprintf (po, "{ProdOrg_%d}", i+1, i+1);
- sprintf (ptime,"{PostTime_%d}", i+1, i+1);
- sprintf (vt, "{VType_%d}", i+1, i+1);
- sprintf (pt, "{ProdType_%d}", i+1, i+1);
- lr_save_var(lr_eval_string(pt),1,0,"temp1");
- lr_save_var(lr_eval_string(po),8,0,"temp2");
- lr_save_var(lr_eval_string(ptime),17,0,"temp3");
- lr_save_var(lr_eval_string(vt),1,0,"temp4");
-
- web_service_call( "StepName=getFisheries_101",
- "SOAPMethod=DataService|DataServiceSoap|getFisheries",
- "ResponseParam=response",
- "Service=DataService",
- "ExpectedResponse=SoapResult",
- "Snapshot=t1377562576.inf",
- BEGIN_ARGUMENTS,
- "userName=IDP",
- "password=IDP",
- "reqSn=1",
- "xml:ps="
- "<ps>"
- "<ProdType>{temp1}</ProdType>"
- "<ProdOrg>{temp2}</ProdOrg>"
- "<Post_Time>{temp3}</Post_Time>"
- "<VType>{temp4}</VType>"
- "</ps>",
- END_ARGUMENTS,
- BEGIN_RESULT,
- "getFisheriesResult/Result=Param_Result",
- "getFisheriesResult/Resource=Param_Resource",
- END_RESULT,
- LAST);
- lr_output_message(lr_eval_string("{Param_Resource}"));
-
-
- lr_save_var(lr_eval_string("{Param_Resource}")+24,29,0,"result");
- FtpLoading(lr_eval_string("{result}"));
- }
- return TRUE;
- }
复制代码 在LoadRunner函数库中看到了这么一个函数 web_service_wait_for_event。实例如下:- web_service_call( "StepName=EchoString_101",
- "SOAPMethod=
- ExtendedECHO_rpc_encoded|ExtendedECHO_rpc_encodedSoap|EchoString",
- "ResponseParam=response",
- "Service=ExtendedECHO_rpc_encoded",
- "AsyncEvent=first_event",
- BEGIN_ARGUMENTS,
- "sec=7",
- "strString=jabberwocky",
- END_ARGUMENTS,
- BEGIN_RESULT,
- "EchoStringResult=first_call",
- END_RESULT,
- LAST );
- web_service_call( "StepName=EchoString_102",
- "SOAPMethod=
- ExtendedECHO_rpc_encoded|ExtendedECHO_rpc_encodedSoap|EchoString",
- "ResponseParam=response",
- "Service=ExtendedECHO_rpc_encoded",
- "AsyncEvent=second_event",
- BEGIN_ARGUMENTS,
- "sec=2",
- "strString=borogoves",
- END_ARGUMENTS,
- BEGIN_RESULT,
- "EchoStringResult=second_call",
- END_RESULT,
- LAST );
- lr_output_message("got event %s",
- web_service_wait_for_event("StepName=WaitHere",
- "Quantifier=ALL",
- "Timeout=10000",
- BEGIN_EVENTS,
- "first_event",
- "second_event",
- END_EVENTS,
- LAST)
- );
复制代码 求助大神讲讲这个函数能够实现我的需求吗? |
|