<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Search Nuggets &#187; ims</title>
	<atom:link href="http://blog.comperiosearch.com/blog/tag/ims/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.comperiosearch.com</link>
	<description>A blog about Search as THE solution</description>
	<lastBuildDate>Mon, 13 Jun 2016 08:59:45 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.9.40</generator>
	<item>
		<title>Querying FSIS with PowerShell</title>
		<link>http://blog.comperiosearch.com/blog/2011/06/21/querying-fsis-powershell/</link>
		<comments>http://blog.comperiosearch.com/blog/2011/06/21/querying-fsis-powershell/#comments</comments>
		<pubDate>Tue, 21 Jun 2011 21:39:45 +0000</pubDate>
		<dc:creator><![CDATA[Marcus Johansson]]></dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[fsis]]></category>
		<category><![CDATA[ims]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://nuggets.comperiosearch.com/?p=510</guid>
		<description><![CDATA[When building IMS search flows in FAST Search for Internet Sites (FSIS), I typically deploy them using the Add-Flow PowerShell cmdlet. One thing that always bugs me, is that there’s no easy way of testing the flows right away from the command-line. Usually, this isn’t a problem; you can always set up a new test [...]]]></description>
				<content:encoded><![CDATA[<p>When building IMS search flows in FAST Search for Internet Sites (FSIS), I typically deploy them using the Add-Flow PowerShell cmdlet. One thing that always bugs me, is that there’s no easy way of testing the flows right away from the command-line. Usually, this isn’t a problem; you can always set up a new test site querying the flow, or just try to run it from your search application.</p>
<p>Still though, it would be cool to have a PowerShell script that runs a query through a flow, and displays the results. Turns out it’s not that hard to build! Though I have to admit it gets a little complex, and is not exactly FSIS standard procedure. But I found it interesting to put together and useful to have around – perhaps you will too.</p>
<p>There’s a link to the source code at the end of this post, and I will discuss the most important parts of the script below. So let’s dive right in! The script takes two parameters: a flow name and a query that will target the ESP default composite field. In this experimental version of the script I haven’t polished the output, and actually only prints the first result document. Feel free to modify it to allow more advanced (arbitrary?) queries and stylish output – just make sure to report back when you’re done!</p>
<p>Here’s a screenshot of what the script produces today:</p>
<p><a href="http://blog.comperiosearch.com/wp-content/uploads/2011/06/FSIS-Query-script.png"><img class="aligncenter" style="padding-left: 0px; padding-right: 0px; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border-width: 0px;" src="http://blog.comperiosearch.com/wp-content/uploads/2011/06/FSIS-Query-script_thumb.png" alt="FSIS Query script" width="575" height="338" border="0" /></a></p>
<p>The IMS nodes expose two external interfaces that clients can use to send query requests: a WCF interface and a HTTP interface. At first look, the HTTP interface probably sounds like the easy way out. But it turns out the FSIS Shell is already prepared to run WCF queries.</p>
<p>How is that you wonder? When you run the built-in FSIS shell, you’ll notice that it preloads the shell with a bunch of important FSIS snap-ins. It also loads a special application configuration, more precisely %FSIS_HOME%\Powershell\Powershell.exe.config. This file defines two important WCF endpoints: NetTcpBinding_IProcessingEngineManager and NetTcpBinding_IProcessingEngine. It also defines which certificate to use in order to secure the communication. This is exactly what we need.</p>
<blockquote><p>There’s one caveat with this approach: you’ll have to run the PowerShell console with your FSIS service user. This is because the certificate is fetched from its personal certificate store. Let me know if you find an elegant way around this.</p></blockquote>
<p>How do we actually run the flow? Well, there is an Execute-Flow cmdlet. No, there are actually two. One from the snap-in EnginePSSnapIn for running flows in general, and one from InteractionEnginePSSnapIn that targets IMS flows. When you start the FSIS shell, they’re loaded in this order:</p><pre class="crayon-plain-tag">Add-PSSnapin HostControllerPSSnapIn
Add-PSSnapin JunoPSSnapin
Add-PSSnapin EnginePSSnapIn
Add-PSSnapin InteractionEnginePSSnapIn</pre><p>Notice the problem? Yup, the one from InteractionEnginePSSnapIn will actually overwrite the one from EnginePSSnapIn. This is most likely a bug in the current FSIS release. But for the purpose of this blog post, it really doesn’t matter. We want the one from InteractionEnginePSSnapIn anyway.</p>
<p>Execute-Flow takes a Context as parameter. This context object is populated with a query and an IMS flow, and is then passed from task to task through the specified flow, until it comes out on the other end – hopefully with some search results attached to it.</p>
<p>Now is probably the time to say that this script won’t work for all types of flows. It depends on what type of tasks you put in your flow, and how you create the actual query that you’ll put on the context object. In this example, I’m using the simplest IMS flow possible: just a flow input, an ESP lookup, and the flow output:</p>
<p><a href="http://blog.comperiosearch.com/wp-content/uploads/2011/06/image.png"><img class="aligncenter" style="padding-left: 0px; padding-right: 0px; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border-width: 0px;" src="http://blog.comperiosearch.com/wp-content/uploads/2011/06/image_thumb.png" alt="image" width="394" height="121" border="0" /></a></p>
<p>So let’s create the context and make sure we target the IMS flow that was supplied when the script was called. The particular class we need is already loaded into the FSIS Shell environment, so it&#8217;s pretty easy:</p><pre class="crayon-plain-tag">$context = New-Object Microsoft.Ceres.InteractionEngine.Services.Context
$context.EnsureRouting().FlowName = $flowName</pre><p>Building the query is harder. To do that, we have to go a little outside the scope of the FSIS shell. We have to use the same assembly that FSIS uses under the hood. Most users would probably never need to do this, but rather use IMS UI Toolkit to build queries and render results.</p>
<p>The DLL we’re interested in is called Microsoft.Ceres.InteractionEngine.ContextModifiers.dll. We load it into PowerShell with the one-liner below. Notice that $env:FSIS_HOME is PowerShell’s way of referencing an environment variable, in this case the installation directory of FSIS.</p><pre class="crayon-plain-tag">[Reflection.Assembly]::LoadFile($env:FSIS_HOME + &quot;AdminUI\site\bin\Microsoft.Ceres.InteractionEngine.ContextModifiers.dll&quot;)</pre><p>After loading this assembly, we can reference classes in the ContextModifiers.Ims namespace. It contains lots of interesting classes for building advanced queries and parsing results. For now, we settle on using the ImsTermsOperator class, which translates into a standard text query. The ImsTermsOperator has several properties that control linguistics, if multiple terms within it should be ANDed or ORed, etc. For now, we just specify the “Terms” property to whatever is passed in when the script is called. Since we&#8217;re not specifying the $searchOp.Scope property, the query will target the default composite field.</p><pre class="crayon-plain-tag">$searchOp = New-Object Microsoft.Ceres.InteractionEngine.ContextModifiers.Ims.ImsTermsOperator
$searchOp.Terms = $query</pre><p>Next step is to add the $searchOp to the context, and for that we need to use a wrapper class called ImsSearch. Take a look in the source code below for the gory details about this. For now, let&#8217;s just skip right to the grand finale: we connect to IMS using Connect-ProcessingEngine, and run the flow with the Execute-Flow cmdlet; passing in the context object and getting back an updated version bundled with the search results:</p><pre class="crayon-plain-tag">Connect-ProcessingEngine $imsHost $imsPort
$context = Execute-Flow $context</pre><p>As the $context variable is serialized during transfer back and forth to IMS, we also need to explicitly parse out the search results, and cast it into an object of type Ims.ImsSearchResults. It looks a little messy, but is actually very straight-forward.</p>
<p>Take a look in the code for yourself: <a href="http://blog.comperiosearch.com/wp-content/uploads/2012/10/Query-IMS-Flow.ps1_.txt">Query-IMS-Flow.ps1</a>.</p>
<p>All of this could of course also be written in your favorite .NET language. Then you could also get around the certificate issue quite easily. I guess I’m just a PowerShell fanboy. <img class="wlEmoticon wlEmoticon-winkingsmile" style="border-style: none;" src="http://blog.comperiosearch.com/wp-content/uploads/2011/06/wlEmoticon-winkingsmile.png" alt="Winking smile" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.comperiosearch.com/blog/2011/06/21/querying-fsis-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to enable WCF tracing in FSIS</title>
		<link>http://blog.comperiosearch.com/blog/2011/01/29/enable-wcf-tracing-fsis/</link>
		<comments>http://blog.comperiosearch.com/blog/2011/01/29/enable-wcf-tracing-fsis/#comments</comments>
		<pubDate>Sat, 29 Jan 2011 17:50:24 +0000</pubDate>
		<dc:creator><![CDATA[Marcus Johansson]]></dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[fsis]]></category>
		<category><![CDATA[ims]]></category>
		<category><![CDATA[wcf]]></category>

		<guid isPermaLink="false">http://nuggets.comperiosearch.com/?p=222</guid>
		<description><![CDATA[When developing client applications using WCF, you’re bound to sooner or later encounter the dreaded “The server was unable to process the request due to an internal error”. This means that the web service threw an unhandled exception, and if you don’t have access to the service itself, you’re simply just out of luck. But [...]]]></description>
				<content:encoded><![CDATA[<p>When developing client applications using WCF, you’re bound to sooner or later encounter the dreaded “The server was unable to process the request due to an internal error”. This means that the web service threw an unhandled exception, and if you don’t have access to the service itself, you’re simply just out of luck.</p>
<p>But many <em>handled</em> exceptions can be equally frustrating. I recently wrote a small demo application, showing a client how to integrate against FSIS from within their particular server environment. Everything looked okay (doesn’t it always :)), but whenever I ran my queries, FSIS just replied with “Socket Connection was aborted”.</p>
<p>A good place to start when debugging WCF problems is to enable tracing. I added the following XML snippet to my app.config, and opened the generated file with Microsoft Service Trace Viewer. Unfortunately for me, there were no additional error messages or hints on what the problem might be.</p>
<p></p><pre class="crayon-plain-tag">&amp;lt;system.diagnostics&amp;gt;
  &amp;lt;sources&amp;gt;
    &amp;lt;source name=&quot;System.ServiceModel&quot;
            switchValue=&quot;Information, ActivityTracing&quot;
            propagateActivity=&quot;true&quot;&amp;gt;
      &amp;lt;listeners&amp;gt;
        &amp;lt;add name=&quot;traceListener&quot;
             type=&quot;System.Diagnostics.XmlWriterTraceListener&quot;
             initializeData=&quot;C:\Client-WcfTrace.svclog&quot; /&amp;gt;
      &amp;lt;/listeners&amp;gt;
    &amp;lt;/source&amp;gt;
  &amp;lt;/sources&amp;gt;
&amp;lt;/system.diagnostics&amp;gt;</pre><p></p>
<p>Digging further, I enabled tracing in the FSIS endpoint as well. The application configuration for the IMS node is by default sitting in the FSIS user’s home directory, more precisely:</p>
<p><code>C:\Users\[FSIS service user]\AppData\Local\FSIS\Nodes\Fsis\InteractionEngineNode1\Node.config</code></p>
<p>Under the System.Diagnostics XML node I added a source tag for System.ServiceModel, so that the whole segment looked like:</p>
<p></p><pre class="crayon-plain-tag">&amp;lt;system.diagnostics&amp;gt;
  &amp;lt;switches&amp;gt;
    &amp;lt;add name=&quot;NodeRunner&quot; value=&quot;Info&quot; /&amp;gt;
    &amp;lt;add name=&quot;Bootstrap&quot; value=&quot;Info&quot; /&amp;gt;
    &amp;lt;add name=&quot;Debug&quot; value=&quot;0&quot; /&amp;gt;
  &amp;lt;/switches&amp;gt;
  &amp;lt;trace autoflush=&quot;false&quot; indentsize=&quot;4&quot;&amp;gt;
    &amp;lt;listeners&amp;gt;
      &amp;lt;remove name=&quot;Default&quot; /&amp;gt;
    &amp;lt;/listeners&amp;gt;
  &amp;lt;/trace&amp;gt;
  &amp;lt;sources&amp;gt;
    &amp;lt;source name=&quot;System.ServiceModel&quot;
            switchValue=&quot;Information, ActivityTracing&quot;
            propagateActivity=&quot;true&quot;&amp;gt;
      &amp;lt;listeners&amp;gt;
        &amp;lt;add name=&quot;wcfTraceListener&quot;
             type=&quot;System.Diagnostics.XmlWriterTraceListener&quot;
             initializeData=&quot;C:\Server-WcfTrace.svclog&quot; /&amp;gt;
      &amp;lt;/listeners&amp;gt;
    &amp;lt;/source&amp;gt;
  &amp;lt;/sources&amp;gt;
&amp;lt;/system.diagnostics&amp;gt;</pre><p></p>
<p>Sure enough! When inspecting the resulting log file in Trace Viewer, I found a red line indicating exactly what the problem was. In my case, I had messed up my certificates: “the remote SSL client failed to provide a required certificate”.</p>
<p><a href="http://blog.comperiosearch.com/wp-content/uploads/2011/01/trace.png"><img class="aligncenter size-full wp-image-224" src="http://blog.comperiosearch.com/wp-content/uploads/2011/01/trace.png" alt="" width="605" height="387" /></a></p>
<p>Read more about <a href="http://msdn.microsoft.com/en-us/library/ms733025%28v=VS.100%29.aspx">WCF tracing on MSDN</a>, and if you haven’t already, make sure to also read my brief introduction to <a href="../2010/11/fast-search-internet-sites/">FAST Search for Internet Sites</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.comperiosearch.com/blog/2011/01/29/enable-wcf-tracing-fsis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
