Grab Input from another service

hyeung
User offline. Last seen 1 year 44 weeks ago. Offline
Joined: 01/22/2010
Points: 30

 I have 2 web service operations. 

1. Get product list

2. Get product availability by ID

I want to create the output with the Product name and ID from 1 and the stock status from 2

Since operation 2 requires a product ID as an input parameter to retrieve data, Join or Merge may not work in this case. I think I need to first get the product list and then feed each of the product ID to 2 to get the results.

How can I generate the results in Wires?

Please advise.

Thanks

 

0
Your rating: None
aishmishra
aishmishra's picture
User offline. Last seen 10 weeks 6 days ago. Offline
Joined: 09/24/2008
Points: 3

Hi,

Since we need the output of service 1 to get output from service 2, a Join or Merge may not work. One approach could be:

i. Invoke service one.

ii. Create a Macro which traverses through the output of service one and calls service 2 with one value at a time and creates an XML document using product name and id from 1 and status from 2 (documentation available at http://www.jackbe.com/prestodocs/v2.7.0/prestolibrary/wwhelp/wwhimpl/api.htm?href=PrestoLibrary.1.238.html).

ii. You will have to write the macro in a text editor or Mashup Studio.

ii. Rest of the implementation can be done in Wires.

Do let us know if this helps.

 

smitchell
smitchell's picture
User offline. Last seen 15 hours 53 min ago. Offline
Joined: 08/29/2008
Points: 34

What Aish suggests will work, although you do not have to create a macro to do this. If the logic of looping through the results for service 1 is specific to this mashup you can just do it in the mashup directly.

What you need is the <foreach> statement that selects the product ID and within <foreach> the invoke statement. You can use <appendresult> to build a combined result from all the invokes, or look at the <foreach> parallel syntax to run the invokes in parallel and get a combined result.

 

Sara, technical writer/jackbe

 

hyeung
User offline. Last seen 1 year 44 weeks ago. Offline
Joined: 01/22/2010
Points: 30

 

I could not get any results from the code below. It works if I change the output to 'Aresult', I believe that has something to do with the <foreach> loop.

  <output name="Cresult" type="document" />

  <constructor outputvariable="parameters">

<web:GetProducts xmlns:web="http://contract5.com/webservices" />

</constructor>

  <invoke service="NorthWind" operation="GetProducts"

inputvariables="parameters" outputvariable="Aresult" />

    <foreach items="$Aresult//GetProductsResponse//GetProductsResult//Product" variable="Bresult">

<appendresult outputvariable="Cresult">

<Bresult />

</appendresult>

</foreach>

I need some help using the <foreach > loop. Thank you.

 

Aresult returns:

 <GetProductsResponse>

    <GetProductsResult>

       <Product>

          <ProductID>77</ProductID>

    ...

       </Product>

    </GetProductsResult>

 </GetProductsResponse>

 

nzblue_fish
nzblue_fish's picture
User offline. Last seen 2 weeks 4 days ago. Offline
Joined: 09/30/2009
Points: 1165

Hi

I can't replicate your webservice feeds but here's a test emml script that should work for you. I've mocked up the two incoming webservices as XML documents just to test it out. It seems to work ok and produces the result shown at the end.

Hope this helps you get mashing ...

Cheers, Innes

<mashup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.jackbe.com/2008-03-01/EMMLSchema/ ../src/schemas/EMMLSpec.xsd"
    xmlns="http://www.jackbe.com/2008-03-01/EMMLSchema" xmlns:macro="http://www.jackbe.com/2008-03-01/EMMLMacro">
    <operation name="test8">
        <output name="result" type="document" />
        <variables>
            <!-- mock some data from the invokes -->
            <variable name="aResult" type="document">
                <GetProductsResponse>
                    <GetProductsResult>
                        <Product>
                            <ProductID>88</ProductID>
                            <ProductName>Widget A</ProductName>
                        </Product>
                        <Product>
                            <ProductID>77</ProductID>
                            <ProductName>Gadget B</ProductName>
                        </Product>
                        <Product>
                            <ProductID>66</ProductID>
                            <ProductName>Dohicky C</ProductName>
                        </Product>
                    </GetProductsResult>
                </GetProductsResponse>
            </variable>
            <variable name="bResult" type="document">
                <GetProductsResponse>
                    <GetProductsResult>
                        <Product>
                            <ProductID>77</ProductID>
                            <StockLevel>100</StockLevel>
                        </Product>
                        <Product>
                            <ProductID>88</ProductID>
                            <StockLevel>200</StockLevel>
                        </Product>
                        <Product>
                            <ProductID>99</ProductID>
                            <StockLevel>1000</StockLevel>
                        </Product>
                    </GetProductsResult>
                </GetProductsResponse>
            </variable>
            <!--
                Used in the join
            -->
            <variable name="prodStockLevels" type="document" />
        </variables>
        <!--
            Join using the ProductID as the key and select the join result fields
            to use, noting that ProductIDs 66 and 99 from each side won't match so
            won't appear in the result
        -->
        <join
            joincondition="$aResult/*:GetProductsResponse/*:GetProductsResult/*:Product/*:ProductID = $bResult/*:GetProductsResponse/*:GetProductsResult/*:Product/*:ProductID"
            outputvariable="result">
            <select name="prodStockLevels">
                <Product>
                    {$aResult/*:ProductID}
                    {$aResult/*:ProductName}
                    {$bResult/*:StockLevel}
                </Product>
            </select>
        </join>
    </operation>
</mashup>

and the result is:

<?xml version="1.0" encoding="UTF-8"?>
<prodStockLevels>
<Product>
<ProductID>88</ProductID>
<ProductName>Widget A</ProductName>
<StockLevel>200</StockLevel>
</Product>
<Product>
<ProductID>77</ProductID>
<ProductName>Gadget B</ProductName>
<StockLevel>100</StockLevel>
</Product>
</prodStockLevels>