Supply XML parameters in a SOAP Service Connection with SharePoint Designer 2010
SharePoint Designers allows to create a data source based on a web service, and then use this data source in a page.
Let’s say you want to display search results in a page. To do so you can use the QueryEx method of the search.asmx web service. This method takes 1 parameter, queryXml, which is an XML representation of a query.
To create the datasource, you click on Data Sources > SOAP Service Connection (in the ribbon). This window appears:
In the Service description location field, type the URL of the search web service. For example: https://yvandev10:6000/_vti_bin/search.asmx?WSDL and click “Connect Now”.
In the parameters, queryXml attribute appears so you can set its value by clicking on “Modify”.
Normally, queryXml looks like the following:
<QueryPacket xmlns="urn:Microsoft.Search.Query" Revision="1000">
<Query domain="QDomain">
<SupportedFormats>
<Format>urn:Microsoft.Search.Response.Document.Document</Format>
</SupportedFormats>
<Context>
<QueryText language="en-US" type="MSSQLFT">SELECT Title, Path, Description, Write, Rank, Size FROM Scope() WHERE CONTAINS(Description, 'SharePoint') AND "Scope" = 'All Sites'</QueryText>
</Context>
<Range><StartAt>1</StartAt><Count>20</Count></Range>
<EnableStemming>false</EnableStemming>
<TrimDuplicates>true</TrimDuplicates>
<IgnoreAllNoiseQuery>true</IgnoreAllNoiseQuery>
<ImplicitAndBehavior>true</ImplicitAndBehavior>
<IncludeRelevanceResults>true</IncludeRelevanceResults>
<IncludeSpecialTermResults>true</IncludeSpecialTermResults>
<IncludeHighConfidenceResults>true</IncludeHighConfidenceResults>
</Query>
</QueryPacket>
But there is a trick to use it in SharePoint Designer: you have to encode XML special character, and put the whole query in 1 line. So it results in the following:
<QueryPacket xmlns="urn:Microsoft.Search.Query" Revision="1000"> <Query domain="QDomain"> <SupportedFormats> <Format>urn:Microsoft.Search.Response.Document.Document</Format> </SupportedFormats> <Context> <QueryText language="en-US" type="MSSQLFT">SELECT Title, Path, Description, Write, Rank, Size FROM Scope() WHERE CONTAINS(Description, 'SharePoint') AND "Scope" = 'All Sites'</QueryText> </Context> <Range><StartAt>1</StartAt><Count>20</Count></Range> <EnableStemming>false</EnableStemming> <TrimDuplicates>true</TrimDuplicates> <IgnoreAllNoiseQuery>true</IgnoreAllNoiseQuery> <ImplicitAndBehavior>true</ImplicitAndBehavior> <IncludeRelevanceResults>true</IncludeRelevanceResults> <IncludeSpecialTermResults>true</IncludeSpecialTermResults> <IncludeHighConfidenceResults>true</IncludeHighConfidenceResults> </Query> </QueryPacket>
that you can type in the queryXml value:
A list of special characters and their encoded value can be found in this article: https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references.
Notepad++ is a good tool to encode string quickly: select the string > TextFX > TextFX Convert > Encore HTML (&<>”).
Finally, you can use the data source in a page through a DataView control. If connection to web service was successful
- you’ll see the DataSource properties in the properties tab
- With Fiddler, while you add the DataView control, a bunch of calls to /_vti_bin/webpartpages.asmx, all resulting in a HTTP 200 (perhaps HTTP 401 before – expected) responses.
If you get an HTTP 500 response instead, the queryXml value is likely not set correctly.
Comments
Anonymous
December 28, 2010
Have you checked this tool: www.aconcaguait.com/sp2010upp.php Does this pass User Profile values to SOAP Datasources as well?Anonymous
August 17, 2011
BTW, the encoding problem is resolved by a hotfix: support.microsoft.com/.../2536592