<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>anantd's blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/anantd/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/anantd/feed.xml</link>
    <description>Technical and non techincal ramblings</description>
    <lastBuildDate>Tue, 16 Apr 2019 04:38:12 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Authentication options for custom application when accessing data from O365</title>
      <link>https://docs.microsoft.com/archive/blogs/anantd/authentication-options-for-custom-application-when-accessing-data-from-o365</link>
      <pubDate>Tue, 02 May 2017 18:18:56 GMT</pubDate>
      <dc:creator><![CDATA[US PSfD]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anantd/?p=175</guid>
      <description><![CDATA[Checkout my new post...]]></description>
      <content:encoded><![CDATA[Checkout my new post at:

https://blogs.msdn.microsoft.com/premier_developer/2017/04/21/authentication-options-for-custom-application-when-accessing-data-from-o365/]]></content:encoded>
    </item>
    <item>
      <title>Why cant PowerShell run loops fast ?</title>
      <link>https://docs.microsoft.com/archive/blogs/anantd/why-cant-powershell-run-loops-fast</link>
      <pubDate>Fri, 25 Jul 2014 10:09:00 GMT</pubDate>
      <dc:creator><![CDATA[US PSfD]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anantd/2014/07/25/why-cant-powershell-run-loops-fast/</guid>
      <description><![CDATA[So recently I had to write a PS script for a customer to loop through a large file and process every...]]></description>
      <content:encoded><![CDATA[<p>So recently I had to write a PS script for a customer to loop through a large file and process every character. Seems simple enough and worked great on sample files, but as soon as you give large files to process the performance of PS script was really bad. I assumed it was due to some FileOption parameter that i was not specifying or Filebuffer size not being appropriate. After some debugging I was able to repro the problem even without a file operation. So basically running a loop in PS is slow. Take a look at this:</p>
<p>So here is what I do: Declare an array, go through each item of array. The difference is almost 200 times in perf. <strong>6 sec</strong> in .net and <strong>10 minutes</strong> in PS.&nbsp;&nbsp;</p>
<table style="width: 695px; height: 222px;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="359">
<p align="center"><strong>PS Code (10 minutes)</strong></p>
</td>
<td valign="top" width="438">
<p align="center"><strong>.net CODE (6 sec)</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="359">
<p>$num = 0<br />$buffersize = 4096*1024*200&nbsp;</p>
<p># declare a buffer</p>
<p>[Byte[]]$ba = new-object Byte[] $buffersize<br />$linecount = 1<br />$start = [System.DateTime]::Now<br />do{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp; $num++&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp; if ($ba[$num] -eq 10) { $linecount++}</p>
<p>&nbsp;&nbsp;&nbsp;}while ($num -lt $buffersize)</p>
<p>$end = [System.DateTime]::Now<br />$time = $end - $start<br />write-host "Time taken -" $time</p>
</td>
<td valign="top" width="438">
<p>static void testloop()<br />{</p>
<p>&nbsp; System.DateTime&nbsp; start = DateTime.Now;<br />&nbsp;&nbsp;int&nbsp; buffer = 4096*1024*200;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp; byte[] b =&nbsp; new byte[buffer];<br />&nbsp; int count&nbsp; = 1;<br />&nbsp; int&nbsp; lastcount = 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp; do&nbsp; {<br />&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if&nbsp; (b[lastcount] == 10) { count++; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp; lastcount++;&nbsp;&nbsp;<br />&nbsp; } while<br />&nbsp; (lastcount &lt; buffer);<br />&nbsp; Console.WriteLine("Time Taken - "&nbsp; + (DateTime.Now&nbsp; - start));<br />}</p>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>After discussion with the PS product team. Found out the reason. So since PS is interpreted vs a compiled .net you would expect some perf difference. But internally what PS does is if a loop iterates for more than 16 times, then on the 16th iteration the content of the loop is compiled dynamically as a .net code and the dynamic method is then invoked inside the loop. Great. The only gotcha being that the dynamically invoked method could be&nbsp;a security risk (think viruses duplicating itself) so .net runs a security check on the stack and that is what is slowing the loop down for long running loops in PS.</p>
<p>Workaround:<br />==================<br />We can declare .net code inside PS using the Add-type command. And this way the dynamically invoked method will encapsulate the loop and the iteration so the security check is only done once. Running the code below I consistently got performance similar to .net if not better in few cases.</p>
<p># declare a buffer<br />$buffersize=1024*4<br />[Byte[]]$ba = new-object Byte[] $buffersize<br />$linecount = 1<br />$ba[30] = 10<br />$ba[300] = 10<br />$start = [System.DateTime]::Now</p>
<p>$source = @"<br />&nbsp;&nbsp; public class myArrayIterator<br />&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static int GetCount(byte[]b, byte tofind)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int count = 1;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int lastcount = 0;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int max = b.Length ;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; do<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (b[lastcount] == tofind) { count++; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastcount++;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } while (lastcount &lt; max);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return count ;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp; }<br />"@</p>
<p>Add-Type -TypeDefinition $source</p>
<p>$count = [myArrayIterator]::GetCount($ba, 10)<br />write-host "Count - " $count</p>
<p>$end = [System.DateTime]::Now<br />$time = $end - $start<br />write-host "Time taken -" $time</p>
<p>&nbsp;</p>
<p>Hope this helps with your long running loops in Powershell.</p>]]></content:encoded>
    </item>
    <item>
      <title>What to do with Timer jobs in SP2013</title>
      <link>https://docs.microsoft.com/archive/blogs/anantd/what-to-do-with-timer-jobs-in-sp2013</link>
      <pubDate>Wed, 18 Jun 2014 09:01:57 GMT</pubDate>
      <dc:creator><![CDATA[US PSfD]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anantd/2014/06/18/what-to-do-with-timer-jobs-in-sp2013/</guid>
      <description><![CDATA[With SP2013 one of the common question developers face is what to do with the custom code they have...]]></description>
      <content:encoded><![CDATA[<p>With SP2013 one of the common question developers face is what to do with the custom code they have implemented using Timer jobs. While writing custom timer jobs can technically still be written it will be highly unadvisable to bring custom code to Sharepoint server.</p>
<p>Here are my suggestions for my customers for using alternatives to Timer jobs in SP2013.</p>
<p>If you look at the basic need for Timer jobs it usually boils down to either performing scheduled tasks and/or that an event has occurred in a SP data structure (List/doc lib/pages). There are sometimes needs for a sync job where a timer job syncs data between two sources.</p>
<p><strong>1. SP Workflow : </strong>SP workflows can be used for doing event based triggers (usually if sending email is involved). Also with Site workflows they can be on long timer delays and can run in a loop to query for data changes and then perform appropriate actions.</p>
<p><strong>2. Events:</strong>&nbsp; List based events can be used to trigger a remote event to manage the data change activity as well.</p>
<p><strong>3. Outside Scheduler : </strong>This is the most similar experience to SP timer jobs except there will be no access to server side OM. Outside schedulers either custom .net schedulers(windows service) or Azure scheduling service can be used to trigger code on a time based fashion to perform the operations. Few people I have seen have used "Task Scheduler" in the OS and I personally do not like that option as I am not sure how well it scales.</p>
<p>Now from these three options I am most interested in the 3rd option.</p>
<p>It would be a cool project to write a custom .net service which is installed as an application and is fully trusted to query for data. This service then runs forever and is scanning a predefined list (read from an xml file), you upload your custom dll to this list along with the schedule information on when to run this dll. The service will eventually pick up the dll along with the schedule and call a predefined method (say "Execute")&nbsp;for you in the dll by reflection. Since the service is fully trusted the code should be able to access any list data and can perform various email operation as long as SMTP are properly configured. This will provide for a drop your dll and schedule to run on a schedule and access SP data. <br />Will let everyone know once I have the code ready for this :). Comments are welcome.</p>]]></content:encoded>
    </item>
    <item>
      <title>US PSFD</title>
      <link>https://docs.microsoft.com/archive/blogs/anantd/us-psfd</link>
      <pubDate>Tue, 18 Jan 2011 12:42:56 GMT</pubDate>
      <dc:creator><![CDATA[US PSfD]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anantd/2011/01/18/us-psfd/</guid>
      <description><![CDATA[Microsoft Premier Services for Developers provide active guidance/advisory and best practices for...]]></description>
      <content:encoded><![CDATA[<p>Microsoft Premier Services for Developers provide active guidance/advisory and best practices for leveraging most of their development team. Learn more here:</p>
<p><a href="http://www.microsoft.com/microsoftservices/en/us/support_premier_devs.aspx">http://www.microsoft.com/microsoftservices/en/us/support_premier_devs.aspx</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Zooming in</title>
      <link>https://docs.microsoft.com/archive/blogs/anantd/zooming-in</link>
      <pubDate>Tue, 01 Aug 2006 10:57:00 GMT</pubDate>
      <dc:creator><![CDATA[US PSfD]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anantd/2006/08/01/zooming-in/</guid>
      <description><![CDATA[Test entry to put myself back on the blog map.]]></description>
      <content:encoded><![CDATA[Test entry to put myself back on the blog map.]]></content:encoded>
    </item>
    <item>
      <title>My experiments with SPS Search and Filtering</title>
      <link>https://docs.microsoft.com/archive/blogs/anantd/my-experiments-with-sps-search-and-filtering</link>
      <pubDate>Tue, 08 Jun 2004 11:48:00 GMT</pubDate>
      <dc:creator><![CDATA[US PSfD]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anantd/2004/06/08/my-experiments-with-sps-search-and-filtering/</guid>
      <description><![CDATA[It's been a long time since my last log. Well I have been busy learning SPS search Filters, protocol...]]></description>
      <content:encoded><![CDATA[<P dir=ltr style="MARGIN-RIGHT: 0px">It's been a long time since my last log. Well I have been busy learning SPS search Filters, protocol handlers and was reading other's blogs rather than writing. Also one thing before I start of with SPS stuff. The timeout attribute I mentioned in my last blog works only with sync calls and would not work with async call/callbacks, I stand corrected on that thanks to Roy Chastain.</P>
<P dir=ltr style="MARGIN-RIGHT: 0px">As soon as I got my feet wet(which basically meant I installed SPS server). Rahul, I am not really sure what I did that irked him off so much that he pushed me into the dark alleys of search, custom Filter and protocol handlers. Comming from the COM world where everything that can be thought of was already documented, the muddy waters of IFilters and protocol handlers were as clear to me as the swamps of florida which I had visited last weekend. So I decided to write my own implementation of IFilter and Protocol Handler. I am done with the Filter part now and would be working on the Protocol Handler comming weeks.I guess the real problem with someone like me who has not dealt much with searching and crawling components is that it's difficult to imagine where and how our component would be fit and who and when would our methods be called. Where here is my take on what I understood of it: Filters based on IFilter for MS Indexing server is what SPS uses to Fitler out contents, this was simple enough. </P>
<P dir=ltr style="MARGIN-RIGHT: 0px">The whole design of SPS search is divided into two individual parts:<BR>1. CRAWLING: In this phase the server will crawl any content source, i.e. a file share, a .html page etc. By crawling it means that it would try to extract text and properties of that document and index those in a flat file index. So a crawler would call a protocol handler based on what type of content source it is, the protocol handler would know how to open that content source and then call the IFilter implementation for the respective File type to get its properties and text.<BR>2. SEARCHING: Once a content source has been indexed any search can be performed on this index. Isn't this cool.<BR>Jumping straight to Filters. Filters are basically written to customize the content of a particular file type so it can be indexed efficiently. So for eg. if my app's document has a .ant extension and it stores the name of users in a struct. I would need a Filter to open the file, read the structures, get out the name inside the struct and save it in the indexer. That is the real power of IFilters. </P>
<P dir=ltr style="MARGIN-RIGHT: 0px">Now how do we write one, heh heh, allright for all those code junkies(me included). Here is a good MSDN link for more technical details:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_SP2003_ta/html/ODC_HowToWriteaFilter.asp?frame=true </P>
<P dir=ltr style="MARGIN-RIGHT: 0px">But basically to summarize Protocol handler would open a content source, get to a file, and based on its extension it would call the Filter that has been registered for that extension to index it. So basically we are interested in these 4 methods in a Filter:<BR>1. Init: This is where you would do initialization for your filter.<BR>2. GetChunk: This method gets called to read the file and get a chunk of text or properties. &nbsp;<BR>3. GetText: <BR>4. GetValue: Once a chunk has been read, GetValue or GetText would be called based on the chunk type that we set in GetChunk till it returns FILTER_E_NO_MORE_TEXT or FILTER_E_NO_VALUES.</P>
<P dir=ltr style="MARGIN-RIGHT: 0px">That is it. That is all it requires to write a filter(well not really you would need to have a good understanding of COM, pointers, variant data types and C++ programming). The simplest thing to get started is the simpFilt sample that comes with SDK. To install the filter:<BR>1. Compile it and regsvr32 the dll.<BR>2. In Regedit goto HKLM\software\Microsoft\SPSSearch\ContentIndexCommon\Filters and add the name of the extension your filter will be crawling and in the default value put the CLSID of your dll.<BR>3. From SPS portal site go to Site Settings-&gt;Configure Search and Indexing-&gt;Include File type&nbsp;&nbsp; and add the extension for your filter.<BR>4. Now add a content source where the file with the registered extension is stored and do a full crawl and voila your filter is up and running. <BR>Probably the best way to get a deeper look is to Open the filter project in VS.net and attach to the msadmn.exe process and put breakpoints on those 4 methods. <BR>Currently&nbsp; I&nbsp; am writing a IFilter for Windows Media files(wmv and wma). It's gonna be pretty cool once its ready. I had some trouble with the Media Format SDK but couple of links from Santosh and I was reading those properties like Arial Font 16. My Filter can crawl the document and get the properties out but the indexer somehow is not indexing them properly. But i hope to sort that out this week.</P>
<P dir=ltr style="MARGIN-RIGHT: 0px">Wow this log turned out to be pretty long but would post the Media filter as soon as its done.</P>]]></content:encoded>
    </item>
    <item>
      <title>Specifying Timeout for remoting calls</title>
      <link>https://docs.microsoft.com/archive/blogs/anantd/specifying-timeout-for-remoting-calls</link>
      <pubDate>Tue, 13 Apr 2004 12:19:00 GMT</pubDate>
      <dc:creator><![CDATA[US PSfD]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anantd/2004/04/13/specifying-timeout-for-remoting-calls/</guid>
      <description><![CDATA[This week while working on a case, I discovered how to set timeout values for Remoting calls which I...]]></description>
      <content:encoded><![CDATA[This week while working on a case, I discovered how to set timeout values for Remoting calls which I though is pretty cool. We have missed this attribute a lot in DCOM. <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; We can specify the timeout attribute on the HttpChannel and that sets the time an Http request will wait in GetResponse() method&nbsp;of HttpWebRequest, before it throws an exception. That in remoting translates to when you make a remoting call(sync or async) the underlying channel will wait in GetResponse() for the remote method to return data for that time, if it does not return any response within the 'timeout' period, it would timeout and throw an exception in your remoting call. Cool isn't it.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This value is set to -1 or infinite lifetime by default, that basically means that remoting calls will block forever(yuckkk.) hence leading to client hanging if the server fails to respond. Now when we talk about async calls, then as soon as you shoot an async request it(underlying remoting) starts a HttpWebRequest and waits in GetResponse() for the async method to complete. Even though your class is not waiting on async call to finish and might be doing some other work in the meanwhile. But when your object tries to see if the async method actually returned an result or not at that point of time it would let you know whether the async method returned within the specified 'timeout' from the time you send the original async request if not then it will throw an exception.
<P>How to set:<BR>==========<BR>Unfortunately I found some bugs related to this property having problem being read from config file. But it works great if you specify it programmatically:</P>
<P><FONT size=2>IDictionary props= new Hashtable();<BR>props[&#8221;timeout&#8221;] = 10000 ;//Wait for 10s in remote call.<BR>//other properties like port etc.<BR>HttpChannel chnl = new HttpChannel(props, .... ,....);</FONT></P>]]></content:encoded>
    </item>
    <item>
      <title>Introducing myself</title>
      <link>https://docs.microsoft.com/archive/blogs/anantd/introducing-myself</link>
      <pubDate>Mon, 23 Feb 2004 23:00:00 GMT</pubDate>
      <dc:creator><![CDATA[US PSfD]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anantd/2004/02/23/introducing-myself/</guid>
      <description><![CDATA[My name is Anant Vijay Dimri and till last fortnight I was working as DSE in OLE/COM team. I worked...]]></description>
      <content:encoded><![CDATA[<P>My name is Anant Vijay Dimri and till last fortnight I was working as DSE in OLE/COM team. I worked on&nbsp;OLE, COM, COM Interop, Remoting technologies for couple of years now. I found remoting to be of my interest though Interop also attracted my attention from time to time. Most of my posts would be in Remoting and Interop.<BR>Currently I am moving to Sharepoint technologies within Microsoft and would continue to share my experiences in sharepoint as well.</P>
<P>Originally from busy city of New Delhi, India, I&nbsp;did my M.S. in Comp. Sc. from Univ of North Carolina. After a brief stint with XP team at Redmond, I joined Microsoft Charlotte.</P>
<P>Now and forever married to my wife Khushbu, we both live in sunny southern Queen city Charlotte.</P>]]></content:encoded>
    </item>
    <item>
      <title>Passing Credentials in .net Remoting</title>
      <link>https://docs.microsoft.com/archive/blogs/anantd/passing-credentials-in-net-remoting</link>
      <pubDate>Mon, 23 Feb 2004 13:25:00 GMT</pubDate>
      <dc:creator><![CDATA[US PSfD]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anantd/2004/02/23/passing-credentials-in-net-remoting/</guid>
      <description><![CDATA[This is my first blog, so jumping straight to the point. One intresting thing that I wanted to share...]]></description>
      <content:encoded><![CDATA[<P>This is my first blog, so jumping straight to the point. One intresting thing that I wanted to share for which I have not seen much documentation but people spending long hours figuring this out is how to pass credentials in .net Remoting. <BR>Basically there would be two kinds of scenarios:<BR><STRONG>1. Passing default credentials:</STRONG> <BR>i.e if a user wants to pass&nbsp; the windows credentials of the process along with the remoting request.In this scenario all you want to do is set the useDefaultCredentials property on the HttpChannel to true either programmatically:<BR><FONT color=#000080 size=2>props[&#8220;useDefaultCredentials&#8220;]=&#8220;true&#8220;<BR></FONT><FONT color=#008000 size=2><FONT color=#000000 size=3><FONT color=#000080 size=2>channel = new HttpClientChannel(ChannelProps, ClientBinFormatter);</FONT><BR></FONT></FONT>or through configuration file:<BR><FONT size=2><FONT color=#0000ff>&lt;</FONT><FONT color=#800000>channel</FONT><FONT color=#ff00ff> </FONT><FONT color=#ff0000>ref</FONT><FONT color=#0000ff>="http"</FONT><FONT color=#ff00ff> </FONT><FONT color=#ff0000>useDefaultCredentials</FONT><FONT color=#0000ff>="true"</FONT><FONT color=#ff00ff> </FONT><FONT color=#0000ff>/&gt;</FONT></FONT></P>
<P><FONT color=#0000ff><FONT color=#000000><STRONG>2. Passing custom Credentials:</STRONG><BR>If you want to specify the username, password at runtime and want to pass it with the remoting request. This has been different with .net 1.0 and .net 1.1.<BR></FONT></FONT><SPAN style="FONT-SIZE: 32pt; FONT-FAMILY: Garamond; text-shadow: auto"><FONT face="Times New Roman"><FONT size=3><STRONG>.net 1.0</STRONG> : All you want to do is set the credentials property on your HttpChannel and all remoting requests through this channel sink will use the specified credentials.<BR></FONT></FONT></SPAN><SPAN style="FONT-SIZE: 111%; FONT-FAMILY: Garamond; text-shadow: auto"><SPAN style="FONT-SIZE: 70%; LEFT: -3.88%; COLOR: #a886e0; FONT-FAMILY: Wingdings; POSITION: absolute; TOP: 0.39em; mso-special-format: bullet; mso-color-index: 5"><FONT face="Times New Roman" size=3>n</FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 20pt; FONT-FAMILY: Garamond; text-shadow: auto"><FONT face="Times New Roman" color=#000080 size=2>ICredential credObj = new NetworkCredential(userName,password,domain);<BR></FONT></SPAN><SPAN style="FONT-SIZE: 20pt; FONT-FAMILY: Garamond; text-shadow: auto"><FONT face="Times New Roman" color=#000080 size=2>Properties["credentials"] = credObj; <BR></FONT></SPAN><SPAN lang=EN-GB style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT face="Times New Roman"><FONT color=#000080 size=2>HttpChannel hc = new HttpChannel(channelProperties,&#8230;, .... );</FONT> </FONT></SPAN></P>
<DIV v:shape="_x0000_s1026">
<DIV class=O style="mso-line-spacing: '100 20 0'; mso-margin-left-alt: 216; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-SIZE: 178%; FONT-FAMILY: Garamond; text-shadow: auto"><SPAN style="FONT-SIZE: 70%; LEFT: -4.53%; COLOR: #ffcc00; FONT-FAMILY: Wingdings; POSITION: absolute; TOP: 0.39em; mso-special-format: bullet; mso-color-index: 6"><FONT face="Times New Roman" size=3>n</FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 32pt; FONT-FAMILY: Garamond; text-shadow: auto"><FONT size=3><FONT face="Times New Roman"><STRONG>.net 1.1</STRONG> </FONT></FONT></SPAN></DIV><SPAN style="FONT-SIZE: 156%; FONT-FAMILY: Garamond; text-shadow: auto">
<DIV class=O1 style="mso-line-spacing: '100 20 0'; mso-margin-left-alt: 468; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-SIZE: 70%; LEFT: -3.88%; COLOR: #a886e0; FONT-FAMILY: Wingdings; POSITION: absolute; TOP: 0.39em; mso-special-format: bullet; mso-color-index: 5"><FONT face="Times New Roman" size=3>n</FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 28pt; FONT-FAMILY: Garamond; text-shadow: auto"><FONT face="Times New Roman" size=3>This behavior is changed in .net 1.1 and now the credentials&nbsp;are needed to be set on each proxy, after&nbsp;you create&nbsp;it. This is easy when doing Server Activated object(SingleCall,&nbsp;Singleton).&nbsp;So for that you can easily do:</FONT></SPAN></DIV>
<DIV class=O1 style="mso-line-spacing: '100 20 0'; mso-margin-left-alt: 468; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-SIZE: 28pt; FONT-FAMILY: Garamond; text-shadow: auto"><SPAN style="FONT-SIZE: 20pt; FONT-FAMILY: Garamond; text-shadow: auto"><FONT face="Times New Roman" color=#000080 size=2>ICredential nc= new NetworkCredential(userName,password,domain);<BR></FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><SPAN style="FONT-SIZE: 70%; LEFT: -3.38%; COLOR: #e5e5ff; FONT-FAMILY: Wingdings; POSITION: absolute; TOP: 0.39em; mso-special-format: bullet; mso-color-index: 3"><FONT face="Times New Roman" color=#000080 size=2>n</FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT face="Times New Roman" color=#000080 size=2>object obj = Activator.GetObject (type, url); </FONT></SPAN></DIV>
<DIV class=O2 style="mso-line-spacing: '100 20 0'; mso-margin-left-alt: 720; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><SPAN style="FONT-SIZE: 70%; LEFT: -3.19%; COLOR: #e5e5ff; FONT-FAMILY: Wingdings; POSITION: absolute; TOP: 0.39em; mso-special-format: bullet; mso-color-index: 3"><FONT face="Times New Roman" color=#000080 size=2>n</FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT face="Times New Roman" color=#000080 size=2>IDictionary dict = ChannelServices.GetChannelSinkProperties(obj); </FONT></SPAN></DIV>
<DIV class=O2 style="mso-line-spacing: '100 20 0'; mso-margin-left-alt: 720; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><SPAN style="FONT-SIZE: 70%; LEFT: -3.38%; COLOR: #e5e5ff; FONT-FAMILY: Wingdings; POSITION: absolute; TOP: 0.39em; mso-special-format: bullet; mso-color-index: 3"><FONT face="Times New Roman" color=#000080 size=2>n</FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT face="Times New Roman" color=#000080 size=2>//set credentials on the proxy object </FONT></SPAN></DIV>
<DIV class=O2 style="mso-line-spacing: '100 20 0'; mso-margin-left-alt: 720; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><SPAN style="FONT-SIZE: 70%; LEFT: -3.38%; COLOR: #e5e5ff; FONT-FAMILY: Wingdings; POSITION: absolute; TOP: 0.39em; mso-special-format: bullet; mso-color-index: 3"><FONT face="Times New Roman" color=#000080 size=2>n</FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT face="Times New Roman"><FONT color=#000080 size=2>dict["credentials"] = nc;</FONT> </FONT></SPAN></DIV>
<DIV class=O style="mso-line-spacing: '100 50 0'; mso-margin-left-alt: 216">&nbsp;</DIV>
<DIV class=O style="mso-line-spacing: '100 50 0'; mso-margin-left-alt: 216"><STRONG>Setting credentials for CAO in .net 1.1<BR></STRONG>The catch with setting credentials on each proxy is that since Client activated objects sends a network request during 'new' or GetObject call, the credentials are already passed before you have your proxy. So to get around this problem if you want to pass custom credentials for CAO objects then we get the proxy to internal remoting object that is responsible for creating object on the server and set the credentials on that first.</DIV>
<DIV class=O style="mso-line-spacing: '100 50 0'; mso-margin-left-alt: 216">1. CAO's are managed by internal Server objects so for CAOs we need to create a proxy to<BR><FONT size=2>&lt;</FONT><A href="http://<localhost>/<vroot>/RemoteActivationService.rem"><FONT size=2>http://&lt;localhost&gt;/&lt;vroot&gt;/RemoteActivationService.rem</FONT></A><FONT size=2>&gt;</FONT><BR>Set credentials on ChannelSink of this internal proxy<BR>2. Now when we register and&nbsp;create the CAO on the client, the 'new' call will use the credentials set on RemoteActivationService.rem proxy.<BR>3. Get the Channelsink of the CAO proxy<BR>4. Set Credentials on the CAO proxy</DIV>
<DIV class=O style="mso-line-spacing: '100 50 0'; mso-margin-left-alt: 216">&nbsp;This is how the sample code will look like: 
<DIV class=O v:shape="_x0000_s1026">
<DIV style="mso-line-spacing: '80 20 0'; mso-margin-left-alt: 216; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT color=#000080 size=2>ChannelServices.RegisterChannel(channel); </FONT></SPAN></DIV>
<DIV style="mso-line-spacing: '80 20 0'; mso-margin-left-alt: 216; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT color=#000080 size=2>//Get a proxy for RemoteActivationService.rem this is an //internal object for CAO's </FONT></SPAN></DIV>
<DIV style="mso-line-spacing: '80 20 0'; mso-margin-left-alt: 216; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT color=#000080 size=2>object obj = Activator.GetObject(typeof(RemObjects.MathObject),</FONT><SPAN style="WIDTH: 14.81%; mso-tab-count: 2"><FONT color=#000080 size=2> </FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><SPAN style="WIDTH: 6.78%; mso-tab-count: 1"><FONT color=#000080 size=2></FONT></SPAN><FONT color=#000080 size=2>"http://localhost:80/RemObjects/RemoteActivationService.rem"); </FONT></SPAN></DIV>
<DIV style="mso-line-spacing: '80 20 0'; mso-margin-left-alt: 216; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT color=#000080 size=2>IDictionary dict = ChannelServices.GetChannelSinkProperties(obj); </FONT></SPAN></DIV>
<DIV style="mso-line-spacing: '80 20 0'; mso-margin-left-alt: 216; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT color=#000080 size=2></FONT></SPAN></DIV>
<DIV style="mso-line-spacing: '80 20 0'; mso-margin-left-alt: 216; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT color=#000080 size=2>//set credentials on the proxy object </FONT></SPAN></DIV>
<DIV style="mso-line-spacing: '80 20 0'; mso-margin-left-alt: 216; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT color=#000080 size=2>dict["credentials"] = nc; </FONT></SPAN></DIV>
<DIV style="mso-line-spacing: '80 20 0'; mso-margin-left-alt: 216; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><FONT size=2><FONT color=#000080><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto">RemotingConfiguration.RegisterActivatedClientType(typeof(RemObjects.MathObject),"http://loc</SPAN><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto">alhost:80/Rembjects/"); </SPAN></FONT></FONT></DIV>
<DIV style="mso-line-spacing: '80 20 0'; mso-margin-left-alt: 216; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT color=#000080 size=2></FONT></SPAN></DIV>
<DIV style="mso-line-spacing: '80 20 0'; mso-margin-left-alt: 216; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT color=#000080 size=2>//get instance of your object </FONT></SPAN></DIV>
<DIV style="mso-line-spacing: '80 20 0'; mso-margin-left-alt: 216; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT color=#000080 size=2>objMath = new RemObjects.MathObject(128); </FONT></SPAN></DIV>
<DIV style="mso-line-spacing: '80 20 0'; mso-margin-left-alt: 216; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT color=#000080 size=2></FONT></SPAN></DIV>
<DIV style="mso-line-spacing: '80 20 0'; mso-margin-left-alt: 216; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT color=#000080 size=2>//get channel sink object for your object and set credentials on that </FONT></SPAN></DIV>
<DIV style="mso-line-spacing: '80 20 0'; mso-margin-left-alt: 216; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT color=#000080 size=2>dict = ChannelServices.GetChannelSinkProperties(objMath); </FONT></SPAN></DIV>
<DIV style="mso-line-spacing: '80 20 0'; mso-margin-left-alt: 216; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><SPAN style="FONT-FAMILY: Garamond; text-shadow: auto"><FONT size=2><FONT color=#000080>dict["credentials"] = nc;</FONT> </FONT></SPAN></DIV>
<DIV style="mso-line-spacing: '80 50 0'; mso-margin-left-alt: 216">&nbsp;</DIV>
<DIV style="mso-line-spacing: '80 50 0'; mso-margin-left-alt: 216">Feel free to give me a feedback on this.</DIV></DIV></DIV></DIV>]]></content:encoded>
    </item>
  </channel>
</rss>