## Service Creation using RR Pairs (Request/Response Pairs)

Service Virtualization allows you to create service using request/response(RR) pairs that contain information in the form of HTTP headers and body. It is convenient to use when your backend server is under development and you don't have recording setup, however you have request-response pairs of that backend.

- Project : A project in service virtualization refers to a directory that consists of one or more inter-related virtualized services.
  User can define various configurations that apply to all the services within that project. Projects provide a way to manage and maintain a cohesive set of virtualized services with a common context or purpose.
- Subproject : It refers to a smaller unit or subset of services within a project. It allows user for further categorization and organisation of virtualized services within the project.

RR pair consists of one request and one or more responses that follow the below naming conventions:

- The file name consists of a prefix, a suffix, and optionally a file extension.
  - The prefix is a unique identifier which is used to tie request and response in a pair. You must use the same prefix in all the file names that correspond to a particular pair.
  - The suffix of a request file is -req.
  - The suffix of a response file is -rsp.

  Example 1:

  - GetLoyaltyReward-req.xml
  - GetLoyaltyReward-rsp.xml

  Here in this pair GetLoyaltyReward is prefix and -req / -rsp is suffix and .xml is file extension

  Example 2: In case you have multiple responses, add a number to the end of each response suffix. Here in this there are four responses.

  - GetLoyaltyReward-req.xml
  - GetLoyaltyReward-rsp.xml
  - GetLoyaltyReward-rsp1.xml
  - GetLoyaltyReward-rsp2.xml
  - GetLoyaltyReward-rsp3.xml

  Request file consists of following sections:

  - HTTP request line (e.g. POST /api/v2/merchants/payment HTTP1.1)
  - Zero or more HTTP headers
  - EMPTY LINE (there should be only one empty line)
  - Payload (XML, JSON, TXT, …)

An example of a REST request file:

POST /api/v2/merchants/payment HTTP/1.1
Accept: application/json
Content-Type: application/json
Content-Length:216
{
"amount": {
"amount": 10.5,
"currency": "USD"
},
"paymentMethod": "wallet",
"PayPalWallet": {
"Balance": 956.23,
"WalletID": "UX876QAC"
},
"transactionChannel": "Web Online"
}

In case of SOAP request, request file can have only payload. (see note for more detail). An example of a SOAP request file:

POST /loyalty/loyaltyservice/v1 HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
Content-Length:479
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope>
<soap:Header>
<v1:request_header>
<v11:requesterName>POS</v11:requesterName>
<v11:requestDate>2013-05-09</v11:requestDate>
</v1:request_header>
</soap:Header>
<soap:Body>
<v1:searchRewards>
<v11:provider>cavisson</v11:provider>
<v11:emailAddress>perfemail1@cavisson.com</v11:emailAddress>
</v1:searchRewards>
</soap:Body>
</soap:Envelope>

Similarly, a response file consists of following sections:

- HTTP response line (e.g. HTTP/1.1 200 OK)
- Zero or more HTTP headers
- EMPTY LINE (there should be only one empty line)
- Body (XML, JSON, TXT, …)

An example of a response file:

HTTP/1.1 200 OK
{
"orderAmount": 10.5,
"currency": "USD",
"completable": true,
"timestamp": "04-15-22/03:05",
"transactionReferences": [
{
"transactionId": 3495717101571,
"transactionType": "InitiateDebit",
"transactionDate": "04-15-22/03:05",
"transactionDesc": "Transaction Accepted",
"status": "Processed",
"paymentMethod": "PayPal"
}
]
}

An example of a SOAP response file:

HTTP/1.1 200 OK
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<searchRewardsResponse xmlns="http://service.cavisson.com/Loyalty/
LoyaltyService/v1" xmlns:ns1="http://schema.cavisson.com/
Loyalty/LoyaltyData/v1">
<ns1:returnCode>0</ns1:returnCode>
<ns1:accounts>
<ns1:account>
<ns1:membershipIdentifier>
<ns1:provider>cavisson</ns1:provider>
<ns1:identifier>841010</ns1:identifier>
</ns1:membershipIdentifier>
<ns1:emailAddress>
<ns1:emailAddress>perfemail1@cavisson.com</ns1:emailAddress>
</ns1:emailAddress>
<ns1:loyaltyCardFlag>false</ns1:loyaltyCardFlag>
<ns1:tier>BASE</ns1:tier>
<ns1:member>
<ns1:phoneNumbers>
<ns1:phoneNumber>
<ns1:phone>1306295190</ns1:phone>
<ns1:type>HOME</ns1:type>
</ns1:phoneNumber>
</ns1:phoneNumbers>
</ns1:member>
</ns1:account>
</ns1:accounts>
</searchRewardsResponse>
</soap:Body>
</soap:Envelope>

## How to Create a Virtual Service Using RR Pairs?

1. A user can select RR files by "Using Files" or directory having RR pairs by "Using Directory" radio button.
2. Next upload selected RR pairs by clicking on "Upload". Once uploaded, the user can see the all request/response pair(s) in "Captured URL List". Selected pair is displayed in lower section wherein Request displays the request header and its payload while Request payload displays the request payload. Similarly, Response displays the response header with its payload while Response Payload displays the response payload.
3. If the user wants to reset the table data, click "Reset".
4. Next click on the "Create Services" which will only create the service while "Create Service and Activate" will create the service and activate the service virtualization server also.

Note:

1. The service name will be created by file name however it is editable, the user needs to click the name and edit it.
2. In case SOAP request does not have a request line then service is created with service url " /cav_soap_service". And other services without request line are added as template in same service.
3. While creating service, service virtualization server does auto correlation i.e. it automatically detects the value in response that matches in the request and replace those values with parameters.