<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>My experiences with .NET 3.0</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/saradhic/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/saradhic/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 03:42:57 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Invoke WCF Service via SQL</title>
      <link>https://docs.microsoft.com/archive/blogs/saradhic/invoke-wcf-service-via-sql</link>
      <pubDate>Wed, 12 Sep 2007 04:47:59 GMT</pubDate>
      <dc:creator><![CDATA[saradhic]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/saradhic/2007/09/12/invoke-wcf-service-via-sql/</guid>
      <description><![CDATA[I was working on SQL SSIS and hit upon a limitation with the web service task in the SSIS package....]]></description>
      <content:encoded><![CDATA[<p style="text-align: justify">I was working on SQL SSIS and hit upon a limitation with the web service task in the SSIS package. The web service SSIS package has known limitations to call WCF web service. 
</p><p style="text-align: justify">To overcome this limitation and to call a WCF service from SQL I thought upon the alternatives available. I came across the SQL CLR functionality. 
</p><p style="text-align: justify">I found that to invoke a web service from SQL (through SQL statements and stored procedures), understanding the capabilities of SQL CLR and exposing a .NET method as a CLR Stored Procedure is very essential.
</p><p style="text-align: justify"><span style="color:#333333; font-size:12pt; text-decoration:underline"><strong>SQL Server 2005 integration with CLR
</strong></span></p><p style="text-align: justify">Microsoft SQL Server now features the integration of the common language runtime (CLR) component of the .NET Framework for Microsoft Windows. The CLR supplies managed code with services such as cross-language integration, code access security, object lifetime management, and debugging and profiling support. For SQL Server users and application developers, CLR integration means that developers can now write stored procedures, triggers, user-defined types, user-defined functions (scalar and table-valued), and user-defined aggregate functions using any .NET Framework language, including Microsoft Visual Basic .NET and Microsoft Visual C#.
</p><p style="text-align: justify"><span style="color:#333333; font-size:12pt; text-decoration:underline"><strong>Creating a WCF client
</strong></span></p><p style="text-align: justify"><span style="color:black; font-size:12pt">To consume a WCF service through SQL, we need to create a client proxy for the WCF service. The steps involved in creating a client are 
</span></p><ul><li><div style="text-align: justify"><span style="color:black; font-size:12pt">Obtain the service contract, binding, and address information for a service endpoint.
</span></div></li><li><div style="text-align: justify"><span style="color:black; font-size:12pt">Create a WCF client using that information.
</span></div></li><li><div style="text-align: justify"><span style="color:black; font-size:12pt">Call operations.
</span></div></li><li><div style="text-align: justify"><span style="color:black; font-size:12pt">Close the WCF client object.
</span></div></li></ul><p style="text-align: justify"><span style="color:black; font-size:12pt">The above steps are sufficient in order to call a WCF service from a .NET managed application. However to invoke the WCF from a SQL statement or Stored Procedure the following additional steps are required
</span></p><ul><li><div style="text-align: justify"><span style="color:black; font-size:12pt">Expose a public static method which in turn calls the WCF service
</span></div></li><li><div style="text-align: justify"><span style="color:black; font-size:12pt">Decorate the static method with SqlFuntion attribute, as below
</span></div></li></ul><p><span style="font-family:Courier New">[<span style="color:#2b91af">SqlFunction</span>(FillRowMethodName = <span style="color:#a31515">"FillRow"</span>, DataAccess = <span style="color:#2b91af">DataAccessKind</span>.Read)]
</span></p><ul><li><div style="text-align: justify"><span style="color:black; font-size:12pt">Provide a FillRow method. The FillRow method acts as a helper method which fills in a row of the result set returned by the table valued function. FillRow method is the place to handle Null values and gives the developer a chance to pass an appropriate value in case the actual result returned by the client is null. 
</span></div></li><li><div style="text-align: justify"><span style="color:black; font-size:12pt">At the command prompt CD to the output directory and execute the sgen command. This creates the &lt;wcf_client_assembly_name&gt;.XmlSerializers.dll library necessary to avoid dynamically generating the serializers used during the invocation of the web service. 
</span></div></li></ul><p style="text-align: justify"><span style="color:#333333; font-size:12pt; text-decoration:underline"><strong>Exposing a WCF client as a SQL CLR Function
</strong></span></p><p style="text-align: justify"><span style="color:black; font-size:12pt">To load the WCF client assembly into SQL, the below steps need to be followed
</span></p><ul><li><div style="text-align: justify"><span style="color:black; font-size:12pt">Enable CLR on SQL by executing the following statement
</span></div><p><span style="font-family:Courier New; font-size:10pt"><span style="color:blue">EXEC</span>
					<span style="color:maroon">sp_configure</span>
					<span style="color:red">'clr enabled'</span><span style="color:gray">,</span> 1
</span></p><p style="text-align: justify"><span style="font-family:Courier New; font-size:10pt"><span style="color:blue">RECONFIGURE</span>
					<span style="color:blue">WITH</span>
					<span style="color:blue">OVERRIDE</span><span style="color:gray">;
</span></span></p></li><li><div style="text-align: justify"><span style="color:black; font-size:12pt">Set the database Trustworthy to ON
</span></div><p><span style="font-family:Courier New; font-size:10pt"><span style="color:blue">ALTER</span>
					<span style="color:blue">DATABASE</span> &lt;database name&gt;
</span></p></li></ul><p style="text-align: justify"><span style="font-family:Courier New; font-size:10pt"><span style="color:blue">SET</span>
			<span style="color:blue">TRUSTWORTHY</span>
			<span style="color:blue">ON</span></span><span style="color:black; font-size:12pt">
		</span></p><ul><li><div style="text-align: justify"><span style="color:black; font-size:12pt">Create the assembly in SQL by using the CREATE Assembly statement as below. Note the use of PERMISSION_SET = UNSAFE. This is required since the CLR based stored procedure bas to cross the database boundary and access external resources.
</span></div><p><span style="font-family:Courier New; font-size:10pt"><span style="color:blue">CREATE</span>
					<span style="color:blue">ASSEMBLY</span> &lt;WCF_Client_Assembly_Name&gt;
</span></p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:blue">FROM</span> &lt;Fully Qualified Path to the assembly file&gt;<span style="color:red">
					</span></span></p><p style="text-align: justify"><span style="font-family:Courier New; font-size:10pt"><span style="color:blue">WITH</span>
					<span style="color:blue">PERMISSION_SET</span>
					<span style="color:gray">=</span>
					<span style="color:blue">UNSAFE</span></span><span style="color:black; font-size:12pt">
				</span></p></li><li><div style="text-align: justify"><span style="color:black; font-size:12pt">Expose the static method in the assembly (uploaded in the previous step) as a SQL Function, like below
</span></div><p><span style="font-family:Courier New; font-size:10pt"><span style="color:blue">CREATE</span>
					<span style="color:blue">FUNCTION</span> &lt;CLR Function Name&gt;<span style="color:gray">(</span>&lt;parameters to the WCF client function<span style="color:gray">)
</span></span></p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:blue">RETURNS</span>
					<span style="color:blue">TABLE
</span></span></p><p><span style="color:gray; font-family:Courier New; font-size:10pt">(
</span></p><p><span style="font-family:Courier New; font-size:10pt">&lt;return values with data type&gt;<span style="color:blue">
					</span></span></p><p><span style="color:gray; font-family:Courier New; font-size:10pt">)
</span></p></li></ul><p><span style="font-family:Courier New; font-size:10pt"><span style="color:blue">AS</span>
			<span style="color:blue">EXTERNAL</span>
			<span style="color:blue">NAME </span>&lt;WCF_Client_Assembly_Name&gt;.&lt;WCF_Client_Class&gt;.&lt;Method&gt;; </span><span style="color:black; font-size:12pt">
		</span></p><p style="text-align: justify"><span style="color:#333333; font-size:12pt; text-decoration:underline"><strong>Additional links</strong></span><span style="color:black">
		</span></p><p>Introducing SQL Server 2005's CLR Integration - <a href="https://www.devsource.com/print_article2/0,1217,a=151093,00.asp">https://www.devsource.com/print_article2/0,1217,a=151093,00.asp</a>
	</p><p><span style="color:black">CLR Integration Programming Model Restrictions - <a href="https://msdn2.microsoft.com/en-us/library/ms403273.aspx"/></span>https://msdn2.microsoft.com/en-us/library/ms403273.aspx<span style="color:black">
		</span></p><p><span style="color:black">What is Windows Communication Foundation - <a href="https://msdn2.microsoft.com/en-us/library/ms731082.aspx"/></span>https://msdn2.microsoft.com/en-us/library/ms731082.aspx</p>]]></content:encoded>
    </item>
    <item>
      <title>Software Architect</title>
      <link>https://docs.microsoft.com/archive/blogs/saradhic/software-architect</link>
      <pubDate>Mon, 11 Jun 2007 10:58:19 GMT</pubDate>
      <dc:creator><![CDATA[saradhic]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/saradhic/2007/06/11/software-architect/</guid>
      <description><![CDATA[Software Architect, a word often used in the industry to refer a person who translates the user's...]]></description>
      <content:encoded><![CDATA[<p>Software Architect, a word often used in the industry to refer a person who translates the user's needs into the technical requirements, so an architect sits on both sides of the fence – the demand side and the supply side. Microsoft has a certification around the same, and is called Microsoft Certified Architect. But looks like there is more focus on this title now and so the reason Microsoft has started a new MSDN site to talk everything about Software Architect called <a href="https://msdn2.microsoft.com/en-us/skyscrapr/default.aspx">Skyscrapr</a>. 
</p><p>I found <a href="https://blogs.msdn.com/mca/archive/2006/08/11/695038.aspx">this</a> an interesting read on the Architect title.</p>]]></content:encoded>
    </item>
    <item>
      <title>Hosting WF Runtime</title>
      <link>https://docs.microsoft.com/archive/blogs/saradhic/hosting-wf-runtime</link>
      <pubDate>Mon, 28 May 2007 14:03:15 GMT</pubDate>
      <dc:creator><![CDATA[saradhic]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/saradhic/2007/05/28/hosting-wf-runtime/</guid>
      <description><![CDATA[Windows Workflow Foundation is a technology from Microsoft to help enterprise application developers...]]></description>
      <content:encoded><![CDATA[<p>Windows Workflow Foundation is a technology from Microsoft to help enterprise application developers in modeling real-world workflows. Using Visual Studio 2005 with the help of <a href="https://www.microsoft.com/downloads/details.aspx?FamilyID=5d61409e-1fa3-48cf-8023-e8f38e709ba6&amp;DisplayLang=en">Visual Studio 2005 extensions</a> for Workflow Extensions, creating a Workflow is a cake walk. Through Visual Studio one can drag-drop activities. 
</p><p>
 </p><p><span style="font-size:14pt"><strong>Workflow Runtime
</strong></span></p><p>To execute a Workflow, create an instance of WorkflowRuntime like below
</p><p style="margin-left: 72pt"><span style="font-family:Courier New; font-size:10pt"><span style="color:#2b91af">WorkflowRuntime</span> workflowRuntime = <span style="color:blue">new</span>
			<span style="color:#2b91af">WorkflowRuntime</span>()
</span></p><p><a href="https://msdn2.microsoft.com/en-us/library/system.workflow.runtime.workflowruntime.aspx">WorkflowRuntime</a> is a class under System.Workflow.Runtime namespace in system.workflow.runtime.dll. As you would assume WorkflowRuntime abstracts out the functionality of creating, hosting and managing multiple workflows. 
</p><p>A Workflowruntime can host, execute and manage multiple workflows simultaneously. All this is done by executing each workflow hosted, on a different thread. Since multiple threads are getting executed, each thread can complete its execution at its own time, these threads needs to be synchronized. Even if a WorkflowRuntime is hosting and executing a single workflow, the main thread on which WorkflowRuntime is getting executed and the thread (spawned by WorkflowRuntime) running to execute the workflow needs to be synchronized. 
</p><p><a href="https://msdn2.microsoft.com/en-us/library/system.threading.autoresetevent.aspx">AutoResetEvent</a> class comes handy to synchronize threads. All a developer need to do is to create an instance of AutoResetEvent class, and call <strong><em>Set</em></strong> and <strong><em>WaitOne</em></strong> methods on the object. The <strong><em>WaitOne</em></strong> methods lets an executing (main) thread to wait for a spawned thread to complete its execution. The spawned thread calls <strong><em>Set</em></strong> method to indicate the completion of its execution.
</p><p style="margin-left: 72pt"><span style="font-family:Courier New; font-size:10pt"><span style="color:#2b91af">AutoResetEvent</span> waitHandle = <span style="color:blue">new</span>
			<span style="color:#2b91af">AutoResetEvent</span>(<span style="color:blue">false</span>);
</span></p><p style="margin-left: 72pt"><span style="font-family:Courier New; font-size:10pt">workflowRuntime.WorkflowCompleted += <span style="color:blue">delegate</span>(<span style="color:blue">object</span> sender, <span style="color:#2b91af">WorkflowCompletedEventArgs</span> e)
</span></p><p style="margin-left: 72pt"><span style="font-family:Courier New; font-size:10pt">{
</span></p><p style="margin-left: 72pt"><span style="font-family:Courier New; font-size:10pt">waitHandle.Set();
</span></p><p style="margin-left: 72pt"><span style="font-family:Courier New; font-size:10pt">};
</span></p><p>Now we have all the stage set to create an instance of a workflow and execute it. WorkflowRuntime has a method <strong><em>CreateWorkflow</em></strong> which takes the workflow type as an argument to create a workflow instance. 
</p><p style="margin-left: 72pt"><span style="color:green; font-family:Courier New; font-size:10pt">// Get the workflow type
</span></p><p><span style="font-family:Courier New; font-size:10pt">
			<span style="color:#2b91af">Type</span> type = <span style="color:blue">typeof</span>(<span style="color:#2b91af">SimpleWorkflow</span>);
</span></p><p>
 </p><p><span style="font-family:Courier New; font-size:10pt">
			<span style="color:green">// Create and start an instance of the workflow
</span></span></p><p><span style="font-family:Courier New; font-size:10pt">            workflowRuntime.CreateWorkflow(type, parameters).Start();
</span></p><p><span style="font-family:Courier New; font-size:10pt">        <span style="color:green">// Wait for the workflow to complete execution
</span></span></p><p><span style="font-family:Courier New; font-size:10pt">            waitHandle.WaitOne();</span>
	</p><p>That's it. That's all is needed to host a Workflow. Isn't it simple?<span style="font-family:Wingdings">J</span>
	</p><p><span style="font-size:14pt"><strong>Real World scenarios</strong></span>
	</p><p>Though hosting WorkflowRuntime with console applications is simple, it's not the only way. Enterprise systems need a better way to host and manage WorkflowRuntime. Microsoft has thought about this and has come-up with different ways of hosting WorkflowRuntime.
</p><p><br/><span style="font-size:14pt"><strong>Hosting Workflows in ASP.NET Applications</strong></span>
	</p><p>If you want your application to have a Web interface, you can host your workflows within an ASP.NET application. 
</p><p>Use the WorkflowRuntime object to access the workflow runtime.  Applications require one instance of the workflow runtime for all the users of the application. It is possible to create this in the Application_Start event in the Global.asax file.
</p><p>Use the Web.config file to configure the runtime.  
</p><p>If you use the WorkflowWebRequestContext object to access the workflow runtime, you cannot add services such as persistence or scheduling services because the workflow is already started. If you try to add services to the runtime when it has already started it will generate an error. Instead, to configure the runtime with services, use the &lt;workflowRuntime&gt; section in the Web.config file:
</p><p>[Web.config]
</p><p>&lt;configuration&gt;
</p><p>    &lt;configSections&gt;
</p><p>        &lt;section name="WorkflowRuntime"
</p><p>            type="WorkflowRuntimeSection, System.Workflow.Runtime" /&gt;
</p><p>    &lt;/configSections&gt;
</p><p>&lt;/configuration&gt;
</p>]]></content:encoded>
    </item>
  </channel>
</rss>