Mashing SharePoint Web Services: Example 3
We will expose the newly published service, Query Operation as a mashup Service.
See Creating Mashups for further details explaining how to use Wires to create Mashups.
- Having launched Wires, locate the newly published Service in the Service pallette.
- Drag the service out onto the canvas and select the Query operation from the drop down list.
The screenshot below shows the complex Input Parameter details for the Query Operation, The Input Parameter expects the user to enter the queryXml as a string.

Unfortunately, the service WSDL schema does not define the content of the queryXml parameter, the parameter must specify a fragment of XML encapsualted as a QueryPacket. Here is an example :
<QueryPacket xmlns='urn:Microsoft.Search.Query'>
<Query>
<SupportedFormats>
<Format>urn:Microsoft.Search.Response.Document.Document</Format>
</SupportedFormats>
<Context>
<QueryText language='en-US' type='STRING'>Jackbe</QueryText>
</Context>
</Query>
</QueryPacket>
The only part we are interested in is the QueryText element content, Jackbe, in the above example.
With Wires being unable to help us build this fragment of XML we are forced to build the XML fragment and then cut and paste it as a string into the input field for the Seach block, as shown below. We can then invoke the search and see what search results are returned.

By default when the search is invoked the preview window will display the response document as a structured XML Tree, unfortunately, as with the Operation Input Parameter, the WSDL Schema does not go as far as defining the content of the Search Response QueryResult, it just defines it as an opaque string.
By switching to the Text view of the response we can see that the QueryResult contains a CDATA element which in turn contains a ResponsePacket element, encapsulating the Search Result.
We can use the Wires ExtractValue Action to extract this QueryResult value in order to process the Search Result in XML form, as shown in the screenshot below. Now the XML Tree View of the extracted SearchResult ResponsePacket shows us that the Search returned a list of Document elements encapsulating each search result item.

Going back to the Search Query Input Parameter, we dont really want to force the user to have to enter the entire fragment of XML each time they perform a search, ideally, we would provide a template Action which constructs the XML Fragment and inserts the Query Text.
We can add such a Template Action and add it to our Wires pallette relatively easily. Instructions on how to add a new Action to Wires are details in this MDC Blog entry by Kishore, it explains how we can create a new macro which we add to the global.emml-macros file, which is used by wires to populate the Action Pallette.
I've created the following macro, QueryPacketTemplate, which just takes a string input, which will be our query text, and creates a fragment of XML as a string, which we can then wire to out SpJackbeSearch Block in Wires.
<macro name="QueryPacketTemplate">
<output name="result" type="string"/>
<presto-meta name="macrotype">user</presto-meta>
<input name="query" type="string"/>
<presto-meta name="type" variable="query" reference="xmldoc">template</presto-meta>
<presto-meta name="label" variable="query">Query Text</presto-meta>
<presto-meta name="help">
<description>build Search Query</description>
<parameters>
<parameter name="query">Search Query Text</parameter>
</parameters>
</presto-meta>
<variable name="resultStr" type="string"/>
<script type="javascript">
<![CDATA[
var rgx=/\[([^\]]+)\]/g;
query=query.replace(rgx,"{$item/$1/string()}");
var resultStr = '<QueryPacket xmlns="urn:Microsoft.Search.Query">'+
'<Query>'+
'<SupportedFormats><Format>urn:Microsoft.Search.Response.Document.Document</Format></SupportedFormats>'+
'<Context>'+
'<QueryText language="en-US" type="STRING">'+
query +
'</QueryText>'+
'</Context>'+
'</Query>'+
'</QueryPacket>';
]]>
</script>
<assign fromvariable="resultStr" outputvariable="result"/>
</macro>
Presto must be restarted if the global.emml-macros file is updated.
The screenshot below shows the completed mashup, the new QueryPacketTemplate action is fed by an Input Parameter block which takes a simple string value as the query text.

- Login or register to post comments
- Email this page










