次の方法で共有


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:

Create Datasource

 

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:

&lt;QueryPacket xmlns=&quot;urn:Microsoft.Search.Query&quot; Revision=&quot;1000&quot;&gt; &lt;Query domain=&quot;QDomain&quot;&gt; &lt;SupportedFormats&gt; &lt;Format&gt;urn:Microsoft.Search.Response.Document.Document&lt;/Format&gt; &lt;/SupportedFormats&gt; &lt;Context&gt; &lt;QueryText language=&quot;en-US&quot; type=&quot;MSSQLFT&quot;&gt;SELECT Title, Path, Description, Write, Rank, Size FROM Scope() WHERE CONTAINS(Description, 'SharePoint') AND &quot;Scope&quot; = 'All Sites'&lt;/QueryText&gt; &lt;/Context&gt; &lt;Range&gt;&lt;StartAt&gt;1&lt;/StartAt&gt;&lt;Count&gt;20&lt;/Count&gt;&lt;/Range&gt; &lt;EnableStemming&gt;false&lt;/EnableStemming&gt; &lt;TrimDuplicates&gt;true&lt;/TrimDuplicates&gt; &lt;IgnoreAllNoiseQuery&gt;true&lt;/IgnoreAllNoiseQuery&gt; &lt;ImplicitAndBehavior&gt;true&lt;/ImplicitAndBehavior&gt; &lt;IncludeRelevanceResults&gt;true&lt;/IncludeRelevanceResults&gt; &lt;IncludeSpecialTermResults&gt;true&lt;/IncludeSpecialTermResults&gt; &lt;IncludeHighConfidenceResults&gt;true&lt;/IncludeHighConfidenceResults&gt; &lt;/Query&gt; &lt;/QueryPacket&gt;

that you can type in the queryXml value:

Edit Datasource

 

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