xml SoapUI:是否可以从 SOAP 消息中的元素自动生成值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3724904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 13:17:33  来源:igfitidea点击:

SoapUI : is it possible to autogenerate the value from an element in a SOAP message?

xmlrandomguidsoapui

提问by Stef Heyenrath

With SoapUIit's possible to send Soap XML message to a WCF service. I've the following SOAP message:

使用SoapUI,可以将 Soap XML 消息发送到 WCF 服务。我有以下 SOAP 消息:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:my="http://myserviceprovider">
   <soap:Header/>
   <soap:Body>
      <my:ProcessOrder>
         <my:Orders>
            <my:Order>
               <my:id>randomid_1234567890</my:id>
               <my:data>ABC</my:data>
            </my:Order>
         </my:Orders>
      </my:ProcessOrder>
   </soap:Body>
</soap:Envelope>

Because the WCF service expects a unique ID for my:id, I would like to know if SoapUI provides functionality to automatically generate a random GUID?

因为 WCF 服务需要my:id的唯一 ID ,我想知道 SoapUI 是否提供自动生成随机 GUID 的功能?

采纳答案by BlackGaff

Rather then a random ID, I would suggest using the times stamp down to the millisecond, as the number will never be duplicated.

而不是随机 ID,我建议使用时间标记到毫秒,因为该数字永远不会重复。

I haven't done this myself, but it looks like you call a string function:

我自己没有这样做过,但看起来你调用了一个字符串函数:

01  ...
02  ...
03   <!-- text within dateEffectiveFrom tag is replaced with a date 10 days from today in yyyy-MM-dd format -->
04   <dateEffectiveFrom>${=  String.format('%tF', new Date() + 10) }</dateEffectiveFrom>
05   
06  <!-- TestSuite property "date" is defined as "${=  String.format('%tF', new Date() + 10) }" -->
07  <!-- Another example where dynamic date is defined as TestSuite property -->
08  <!-- and then SOAP Request can refer to this TestSuite property as shown below -->
09   <dateEffectiveFrom>${#TestSuite#date}</dateEffectiveFrom>
10  ...
11  ...

http://onebyteatatime.wordpress.com/2009/04/18/soapui-tips-n-tricks-part-2/

http://onebyteatatime.wordpress.com/2009/04/18/soapui-tips-n-tricks-part-2/

回答by bkaid

This will generate a globally unique id:

这将生成一个全局唯一的 id:

${=java.util.UUID.randomUUID()}

回答by vkrams

I have just used the below code to generate random nummber in my SOAPUI request and it worked without any problem. This will generate a random number of 10 digits.

我刚刚使用下面的代码在我的 SOAPUI 请求中生成随机数,并且它没有任何问题。这将生成一个 10 位数的随机数。

<val:Id UniqueID="${=org.apache.commons.lang.RandomStringUtils.randomNumeric(10)}"/>

<val:Id UniqueID="${=org.apache.commons.lang.RandomStringUtils.randomNumeric(10)}"/>

If you want to change number of digits, just change the desired number of digits in randomNumeric()method.

如果要更改位数,只需在randomNumeric()方法中更改所需的位数即可。