<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>gubus 2.0</title>
	<atom:link href="http://gubus2.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://gubus2.wordpress.com</link>
	<description></description>
	<lastBuildDate>Wed, 12 Oct 2011 21:50:06 +0000</lastBuildDate>
	<language>hu</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='gubus2.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>gubus 2.0</title>
		<link>http://gubus2.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://gubus2.wordpress.com/osd.xml" title="gubus 2.0" />
	<atom:link rel='hub' href='http://gubus2.wordpress.com/?pushpress=hub'/>
		<item>
		<title>WCF használata vastag kliens alkalmazásoknál II.</title>
		<link>http://gubus2.wordpress.com/2010/12/25/wcf-hasznalata-vastag-kliens-alkalmazasoknal-ii/</link>
		<comments>http://gubus2.wordpress.com/2010/12/25/wcf-hasznalata-vastag-kliens-alkalmazasoknal-ii/#comments</comments>
		<pubDate>Sat, 25 Dec 2010 09:03:59 +0000</pubDate>
		<dc:creator>gubus</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://gubus2.wordpress.com/?p=236</guid>
		<description><![CDATA[A vastag kliens alkalmazásunk Entity Framework entitásokat kér el a szervertől WCF-en keresztül. A kliens és a szerver oldal közös entitás típusokat használ úgy, hogy a kliens oldali WCF proxy generálásakor a közös entitás assembly-ben található típusokat használja fel a generátor. (&#8220;Resuse types from referenced assemblies&#8221; beállítás az &#8220;Add Service Reference&#8221; funkciónál a Visual Studio-ban) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=236&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A vastag kliens alkalmazásunk Entity Framework entitásokat kér el a szervertől WCF-en keresztül. A kliens és a szerver oldal közös entitás típusokat használ úgy, hogy a kliens oldali WCF proxy generálásakor a közös entitás assembly-ben található típusokat használja fel a generátor. (&#8220;Resuse types from referenced assemblies&#8221; beállítás az &#8220;Add Service Reference&#8221; funkciónál a Visual Studio-ban)</p>
<p>A proxy generálás viszont nem működik, ha az entitások egy része tartalmaz körkörös referenciákat, mert akkor a generálás kivételre fut:</p>
<blockquote><p>Error: Cannot import wsdl:portType<br />
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter<br />
Error: Referenced type &#8230; with data contract name &#8216;&#8230;&#8217; in namespace &#8216;&#8230;&#8217; cannot be used since it does not match imported DataContract. Need to exclude this type from referenced types.</p></blockquote>
<p>A hibáról itt van egy összefoglaló:</p>
<p><a href="http://blogs.msdn.com/b/distributedservices/archive/2010/02/04/wcf-client-issue-with-reuse-types-from-referenced-assemblies.aspx">WCF Client Code Generation &#8211; Issue with &#8220;Reuse types from referenced assemblies&#8221; option in Add Service Reference</a></p>
<p>Workaround gyanánt az entitásoknál ki kell kapcsolni a körkörös hivatkozást (&#8220;IsReference=false&#8221; ), és így kell generálni a proxy-t, majd utána újra vissza lehet kapcsolni a körkörös hivatkozást.</p>
<p>És ennél a pontnál lett világosság: hogyha körkörös referenciát használunk, akkor az már rég nem interop webszolgáltatás. Sőt, mivel kliens oldalon és szerver oldalon is .NET van, ez nem is igény, és sokkal egyszerűbb, ha a contract is közös, és  egyáltalán nem lenne kliens proxy generálás. Szóval a WSDL-en keresztüli interfészt csak akkor érdemes használni, ha igény is van rá&#8230;</p>
<p><a href="http://wcfsecurity.codeplex.com/wikipage?title=When%20should%20I%20use%20a%20channel%20factory?">When should I use a channel factory?</a></p>
<blockquote><p>Use a ChannelFactory when you control both ends of the wire and would rather code directly against the same CLR interface instead of manually keeping the WSDL interface in sync. Instead of using WSDL as the shared contract, you use a shared &#8220;interface assembly&#8221;. </p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gubus2.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gubus2.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gubus2.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gubus2.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gubus2.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gubus2.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gubus2.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gubus2.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gubus2.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gubus2.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gubus2.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gubus2.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gubus2.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gubus2.wordpress.com/236/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=236&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gubus2.wordpress.com/2010/12/25/wcf-hasznalata-vastag-kliens-alkalmazasoknal-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/395eea308be2d771d18b9305b854e95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gubus</media:title>
		</media:content>
	</item>
		<item>
		<title>WCF használata vastag kliens alkalmazásoknál I.</title>
		<link>http://gubus2.wordpress.com/2010/12/25/wcf-hasznalata-vastag-klienses-alkalmazasoknal-i/</link>
		<comments>http://gubus2.wordpress.com/2010/12/25/wcf-hasznalata-vastag-klienses-alkalmazasoknal-i/#comments</comments>
		<pubDate>Sat, 25 Dec 2010 08:51:08 +0000</pubDate>
		<dc:creator>gubus</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://gubus2.wordpress.com/?p=222</guid>
		<description><![CDATA[Néha kliens alkalmazásokban látni a következő WCF hívási mintát: A probléma a fenti kóddal az, hogy a kliens minden alkalommal újraépíti a WCF kommunikációt a szerver felé, ami több erőforrásba kerül, mintha egy már megnyitott proxy-n hívná meg a szervert. Fontos az is, hogy a proxy objektum Fault állapotba kerülhet akkor, ha olyan katasztrofális hiba [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=222&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Néha kliens alkalmazásokban látni a következő WCF hívási mintát: </p>
<pre class="brush: csharp;">
using (var client = new FooServiceReference.FooServiceClient(&quot;myBinding&quot;))
{
	var f = client.GetFoo();
}
</pre>
<p>A probléma a fenti kóddal az, hogy a kliens minden alkalommal újraépíti a WCF kommunikációt a szerver felé, ami több erőforrásba kerül, mintha egy már megnyitott proxy-n hívná meg a szervert. </p>
<p>Fontos az is, hogy a proxy objektum Fault állapotba kerülhet akkor, ha olyan katasztrofális hiba keletkezett a kliens-szerver kommunikáció közben, melynél  nem folytatható tovább a kommunikáció.<br />
Példa a Fault állapot bekövetkeztére:<br />
- reliable session használatakor a hívás timeout-ra fut,<br />
- a szerver SOAP Fault üzenetet küld vissza (kivételt dobott a szerver),<br />
- a kommunikáció iniciliazálásakor az ICommunicationObject.Open() hívás nem sikerül,<br />
- session alapú kapcsolatnál olyan protokoll vagy szerver hiba keletkezik, amely miatt a session érvénytelen lesz.</p>
<p>Ha a proxy példány Fault állapotba kerül, akkor nem lehet tovább használni, nem szabad Close()-t hívni rajta (kivételt dob), és az Abort() meghívásával kell felszabadítani az általa lefoglalt erőforrásokat.</p>
<p>A fenti minta így hibásan viselkedik a Fault állapot bekövetkeztekor, mert a proxy-n hívott Dispose() a Close()-t hívja meg, ami pedig Fault állapotban a Dispose() elszállását fogja okozni, tehát egy kommunikációs kivétel feldolgozása közben keletkezni fog egy másik, az eredeti hibát elfedő kivétel. Erre a hibára remek körbebástyázós megoldást találtak ki Redmondban:</p>
<p><a href="http://msdn.microsoft.com/en-us/library/aa355056.aspx">Avoiding Problems with the Using Statement</a></p>
<p><a href="http://social.msdn.microsoft.com/forums/en-US/wcf/thread/4cdc67e0-3069-4d3b-b94f-27e2b8ff4429/">AnswerJuly CTP &#8211; Guidance on factory close and message faults</a></p>
<p>Csak a try-catch beágyazást ipari méretben alkalmazva spagetti kódot fog eredményezni.  </p>
<p>A hatékonyság miatt az is kívánatos lenne, ha az alkalmazás az induláskor hozná létre és inicializálná a proxy objektumokot, ezt a meglévő proxy-t használná az egész élete alatt, és ha az Faulted állapotva kerülne, akkor automatikusa zárná a proxy-t, és nyitná az újat.</p>
<p>A problémát elég jól részletezi a következő két cikk:</p>
<p><a href="http://blogs.msdn.com/b/wenlong/archive/2007/10/27/performance-improvement-of-wcf-client-proxy-creation-and-best-practices.aspx">Performance Improvement for WCF Client Proxy Creation in .NET 3.5 and Best Practices</a></p>
<p><a href="http://wcfguidanceforwpf.codeplex.com/">WCF Guidance for WPF Developers</a></p>
<p>Ezek után mindenki szépen neki is foghat a saját barkács proxy kezelőjének megírásához:</p>
<p>1) <a href="http://blog.weminuche.net/2008/08/test-post.html">WCF Client Proxy IDisposable &#8211; Generic WCF Service Proxy </a><br />
A megoldás a Fault állapotba kerülést jól kezeli, de minden hívásnál új Channel-t és ChannelFactory-t hoz létre, ami viszont a sebességnek nem tesz jót.</p>
<p>2. <a href="http://wcfproxygenerator.codeplex.com/">Exception Handling WCF Proxy Generator</a><br />
Egy Visual Studio extension, melyet <a href="http://www.google.hu/search?q=Michele+Leroux+Bustamante">Michele Leroux Bustamante</a>  fejlesztett ki.<br />
Jellemzők:<br />
- Visual Studio 2008 alá készült az extension<br />
- az extension a ExceptionHandlingProxyBase ősből leszármaztatott proxy osztályokat gyárt. A ExceptionHandlingProxyBase a hölgy saját fejlesztése, egy általános kliens, gyakorlatilag egy alapoktól újraírt ClientBase-nek felel meg.</p>
<p>A megoldás működik, precíz, és látszik a befektetett munka, de mostanában a csapból is a kódgenerátorok folynak, és a plusz bonyolultságtól meg a plusz macerától idegbajt kapok.</p>
<p>3. <a href="http://blog.softwareishardwork.com/2008/10/code-camp-talk-going-proxy-less-wcf.html">Going Proxy-less &#8211; The WCF Proxy Factory</a></p>
<p>Nem tűnik elterjedt, vagy kipróbált dolognak. </p>
<p>4. Christian Weyer elődása és példaprogramjai</p>
<p><a href="http://weblogs.thinktecture.com/cweyer/2009/03/techdays-sweden-2009-presentation-slides-and-demos-for-wcf-tips-tricks-session.html">TechDays Sweden 2009: Presentation slides and demos for &#8216;WCF Tips &amp; Tricks&#8221; session</a></p>
<p>Az előadás fóliái jók, viszont a példaprogramok a szerző Thinktecture.ServiceModel.dll osztálykönyvtárát használják, melynek nincs forráskódja, és maga az assembly is csak demonstrációs célból van publikálva. </p>
<p>5. <a href="http://wcfcontrib.codeplex.com/">WCF Contrib</a>  </p>
<p>A WCF Contrib osztálykönyvtárat <a href="http://blogs.microsoft.co.il/blogs/zuker/">Amir Zuker</a>  készítette, gyakorlatilag ez is egy saját WCF kliens implementáció, de vannak szerver oldali kiegészítései is. Az előző mellett ez tűnik a legátfogóbb megoldásnak, példaprogamok vannak, viszont dokumentáció  kevés. Támogatja az aszinkron hívásokat is.</p>
<p>6. Csak szinkron hívásokra egy egyszerűbb megoldás</p>
<p>Először is a ClientBase-t meg kell patkolni egy kicsit:</p>
<pre class="brush: csharp;">
namespace WcfTools
{
    using System.ServiceModel;

    internal class ClientBaseEx&lt;TInterface&gt; : ClientBase&lt;TInterface&gt;
           where TInterface : class
    {
        public ClientBaseEx(string endpointConfigurationName)
            : base(endpointConfigurationName)
        {

        }

        public ClientBaseEx(string endpointConfigurationName, string remoteAddress)
            : base(endpointConfigurationName, remoteAddress)
        {

        }

        /// &lt;summary&gt;
        /// Protected field published with internal access
        /// &lt;/summary&gt;
        internal TInterface Proxy
        {
            get { return Channel; }
        }

        protected override TInterface CreateChannel()
        {
            return base.CreateChannel();
        }
    }
}
</pre>
<p>Utána készül egy wrapper, mely a ClientBaseEx segítségével hívja meg a szervert:</p>
<pre class="brush: csharp;">
namespace WcfTools
{
    using System;
    using System.Runtime.InteropServices;
    using System.Security;
    using System.ServiceModel;
    using log4net;

    public class SafeClient&lt;TInterface&gt; where TInterface : class
    {
        protected static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        #region Static singleton instance
        private static SafeClient&lt;TInterface&gt; instance = new SafeClient&lt;TInterface&gt;();

        public static SafeClient&lt;TInterface&gt; Instance
        {
            get { return SafeClient&lt;TInterface&gt;.instance; }
        }
        #endregion
        #region Private variables
        private ClientBaseEx&lt;TInterface&gt; clientProxy = null;
        private object lockObj = new object();

        /// &lt;summary&gt;
        /// Csak akkor ad a Proxy mező értéket, ha Connect() meghívásra kerül.
        /// &lt;/summary&gt;
        private bool isConnected = false;
        #endregion
        #region Public properties

        public bool BasicAuthenticationEnabled { get; set; }
        public string BasicAuthenticationUserName { get; set; }
        public SecureString BasicAuthenticationPassword { get; set; }
        public string EndpointConfigurationName { get; set; }
        public string RemoteAddressDirectoryUrl { get; set; }
        public string RemoteAddressServiceFile { get; set; }

        /// &lt;summary&gt;
        /// Webszolgáltatás interfésze
        /// &lt;/summary&gt;
        public TInterface Proxy
        {
            get
            {
                if (log.IsDebugEnabled) log.Debug(&quot;Start&quot;);

                TInterface result = null;

                lock (lockObj)
                {
                    if (isConnected)
                    {
                        CheckClientIsOpened();
                        result = clientProxy.Proxy;
                    }
                    else
                    {
                        if (log.IsDebugEnabled) log.Debug(&quot;Not connected!&quot;);
                    }
                }

                if (log.IsDebugEnabled) log.Debug(&quot;End&quot;);

                return result;
            }
        }

        #endregion
        #region Public functions
        /// &lt;summary&gt;
        /// Kapcsolódás
        /// &lt;/summary&gt;
        public void Connect()
        {
            if (log.IsDebugEnabled) log.Debug(&quot;Start&quot;);

            lock (lockObj)
            {
                // a proxy ne a régi legyen, mert az autentikációs adatok lehet változtak
                DisconnectInternal();
                CheckClientIsOpened();
                isConnected = true;
            }

            if (log.IsDebugEnabled) log.Debug(&quot;End&quot;);
        }

        /// &lt;summary&gt;
        /// Kapcsolat bontása
        /// &lt;/summary&gt;
        public void Disconnect()
        {
            if (log.IsDebugEnabled) log.Debug(&quot;Start&quot;);

            lock (lockObj)
            {
                DisconnectInternal();
            }

            if (log.IsDebugEnabled) log.Debug(&quot;End&quot;);
        }

        #endregion
        #region Private functions

        /// &lt;summary&gt;
        /// Kapcsolat ellenőrzése: szükség esetén bontás, és újranyitás
        /// &lt;/summary&gt;
        private void CheckClientIsOpened()
        {
            if (clientProxy != null)
            {
                if (clientProxy.State == CommunicationState.Faulted)
                {
                    if (log.IsDebugEnabled) log.Debug(&quot;State == CommunicationState.Faulted, aborting...&quot;);

                    try
                    {
                        clientProxy.Abort();
                    }
                    finally
                    {
                        clientProxy = null;
                    }
                }
                else if (clientProxy.State == CommunicationState.Closed)
                {
                    if (log.IsDebugEnabled) log.Debug(&quot;State == CommunicationState.Closed.&quot;);
                    clientProxy = null;
                }
            }

            if (clientProxy == null)
            {
                if (log.IsDebugEnabled) log.Debug(&quot;Creating WCF proxy....&quot;);

                //  a könyvtár jelet a végére tesszük, ha nincs ott, mert különben az sikertelen lesz az összefűzés
                this.RemoteAddressDirectoryUrl = CheckTailSlash(this.RemoteAddressDirectoryUrl);

                Uri uriMain = new Uri(this.RemoteAddressDirectoryUrl);
                Uri uriChild = new Uri(uriMain, this.RemoteAddressServiceFile);

                if (log.IsDebugEnabled) log.DebugFormat(&quot;Url: '{0}'&quot;, uriChild);

                clientProxy = new ClientBaseEx&lt;TInterface&gt;(this.EndpointConfigurationName, uriChild.ToString());

                if (BasicAuthenticationEnabled)
                {
                    clientProxy.ClientCredentials.UserName.UserName = this.BasicAuthenticationUserName;
                    clientProxy.ClientCredentials.UserName.Password = SecureStringToString(this.BasicAuthenticationPassword);
                }

                clientProxy.Open();

                if (log.IsDebugEnabled) log.Debug(&quot;Proxy OK.&quot;);
            }
        }

        private static string CheckTailSlash(string data)
        {
            string result = data.Trim();

            if (result.Length &gt; 0)
            {
                char last = result[result.Length - 1];
                if (last != '/')
                {
                    result += &quot;/&quot;;
                }
            }

            return result;
        }

        private void DisconnectInternal()
        {
            try
            {
                if (clientProxy != null)
                {
                    try
                    {
                        if (clientProxy.State == CommunicationState.Faulted)
                        {
                            clientProxy.Abort();
                        }
                        else
                        {
                            clientProxy.Close();
                        }
                    }
                    finally
                    {
                        clientProxy = null;
                    }
                }
            }
            finally
            {   // mindegy mi történt, a kapcsolat bontva van
                isConnected = false;
            }
        }

        private static string SecureStringToString(SecureString value)
        {
            IntPtr bstr = Marshal.SecureStringToBSTR(value);

            try
            {
                return Marshal.PtrToStringBSTR(bstr);
            }
            finally
            {
                Marshal.FreeBSTR(bstr);
            }
        }

        #endregion
    }
}
</pre>
<p>Példa a használatra:</p>
<pre class="brush: csharp;">
// starting fat client
var client = new SafeClient&lt;FooServiceReference.IFooService&gt;();
client.EndpointConfigurationName = &quot;myBinding&quot;;
client.RemoteAddressDirectoryUrl = &quot;http://localhost:52008/&quot;;
client.RemoteAddressServiceFile = &quot;FooService.svc&quot;;
client.Connect();

...

// fat client using same SafeClient&lt;T&gt; instance
client.Proxy.GetFoo();

try
{
	client.Proxy.GetFooTimeout();
}
catch (Exception ex)
{
	log.Error(ex);
}

try
{
	client.Proxy.GetFooFaulted();
}
catch (Exception ex)
{
	log.Error(ex);
}

client.Proxy.GetFoo();

...

//  fat client stopping
client.Disconnect();
</pre>
<p>A vastag kliensnek annyi dolga van, hogy induláskor építse fel a kapcsolatot, és utána a SafeClient példányt őrizgesse, és rajta keresztül hívja a szervert.<br />
A SafeClient rendelkezik egy Instance nevű singleton példánnyal is, tehát akár saját példány nélkül is lehet használni.</p>
<p>Mikor érdemes külön példányokat használni:<br />
- ha ugyanazt az interfészt más-más autentikációs beállításokkal kell hívni, mert ilyenkor nem lenne szerencsés, ha keverednének a szerveren az azonosítási információk.<br />
- többszálú működésnél, ha két szál egyidőben hívja a szervert, és az egyik Fault állapotba billenti a proxy-t, akkor az a másik, még ugyanazzal a proxy példánnyal dolgozó szálra is hatással lesz. Ha ez  zavaró, akkor szálanként kell példányokat használni, és valami pool-t kell képezni.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gubus2.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gubus2.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gubus2.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gubus2.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gubus2.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gubus2.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gubus2.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gubus2.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gubus2.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gubus2.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gubus2.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gubus2.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gubus2.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gubus2.wordpress.com/222/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=222&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gubus2.wordpress.com/2010/12/25/wcf-hasznalata-vastag-klienses-alkalmazasoknal-i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/395eea308be2d771d18b9305b854e95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gubus</media:title>
		</media:content>
	</item>
		<item>
		<title>How to sign with a timestamp and OCSP in C# &#8211; smart card support</title>
		<link>http://gubus2.wordpress.com/2010/12/25/how-to-sign-with-a-timestamp-and-ocsp-in-c-smart-card-support/</link>
		<comments>http://gubus2.wordpress.com/2010/12/25/how-to-sign-with-a-timestamp-and-ocsp-in-c-smart-card-support/#comments</comments>
		<pubDate>Sat, 25 Dec 2010 08:11:02 +0000</pubDate>
		<dc:creator>gubus</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://gubus2.wordpress.com/?p=219</guid>
		<description><![CDATA[The samples of itextsharp does not cover the situatuion when the certificate is on the smart card AND the signature need timestamp. 1. First sample: Sign without timestamp and with smart card How to sign with a smartcard using an external signature dictionary with iTextSharp and .NET 2.0 This sample uses the SignedCms class of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=219&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://itextpdf.sourceforge.net/howtosign.html">samples of itextsharp</a> does not cover the situatuion when the certificate is on the smart card AND the signature need timestamp.</p>
<p> 1. First sample: Sign without timestamp and with smart card</p>
<p><a href="http://itextpdf.sourceforge.net/howtosign.html#signextitextsharp2">How to sign with a smartcard using an external signature dictionary with iTextSharp and .NET 2.0</a></p>
<p>This sample uses the SignedCms class of the .NET BCL. The SignedCms class creates the complete PKCS#7 message, and it supports when the certificate is on the smart card, but the signature doesn&#8217;t have a timestamp. This class is sealed, and no possibility to extend the data with timetamp information.</p>
<p>2. Second sample: Sign with timestamp and without smart card</p>
<p><a href="http://itextpdf.sourceforge.net/howtosign.html#signtsocspcs">How to sign with a timestamp and OCSP in C#</a></p>
<p>The second sample creates the PKCS#7 message with the Bouncy Castle Crypto API, which is packaged with the iTextSharp. The Bouncy Castle API calculates the signature HASH with the private key value of the X509 certificate, and therefore the smart card certificate is useless for this scenario. </p>
<p>The key in this problem is the SetExternalDigest method: if I can calculate the SHA1withRSA HASH with an external component, then the Bouncy Castle API can use the external value.<br />
The RSACryptoServiceProvider class can create SHA1withRSA HASH, but it doesn&#8217;t support the smart card too. The reliable solution is the WINAPI, it supports the smart card.</p>
<p>The sample C# code below uses the <a href="http://blogs.msdn.com/b/alejacma/archive/2007/11/23/p-invoking-cryptoapi-in-net-c-version.aspx">CryptoAPI PInvoke helper class </a>from <a href="http://blogs.msdn.com/b/alejacma/">Alejandro Campos Magencio</a>.</p>
<pre class="brush: csharp;">
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using iTextSharp.text.pdf;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Security;

namespace PdfSignerTest
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine(&quot;Start&quot;);

                string inputFileName = @&quot;..\..\..\Report.pdf&quot;;
                string outputFileName = @&quot;..\..\..\Signed.pdf&quot;;
                string timeStampUrl = &quot;http://www.xxxx.com/timestamp.cgi&quot;;

                using (FileStream inputPdfStream = new FileStream(inputFileName, FileMode.Open, FileAccess.Read))
                {
                    using (FileStream outputPdfStream = new FileStream(outputFileName, FileMode.Create, FileAccess.Write))
                    {
                        X509Certificate2 card = SelectCertificate();

                        SignPdf(card, inputPdfStream, outputPdfStream, false, &quot;Test Reason&quot;, &quot;Test Location&quot;, &quot;Test Contact&quot;, timeStampUrl, &quot;teszt&quot;, &quot;teszt&quot;);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                Console.WriteLine(&quot;Done.&quot;);
                Console.ReadLine();
            }
        }

        /// &lt;summary&gt;
        ///
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;certificate&quot;&gt;smart card certificate&lt;/param&gt;
        /// &lt;param name=&quot;inputPdfStream&quot;&gt;input PDF&lt;/param&gt;
        /// &lt;param name=&quot;outputPdfStream&quot;&gt;output PDF (signed)&lt;/param&gt;
        /// &lt;param name=&quot;append&quot;&gt;append if &lt;CODE&gt;true&lt;/CODE&gt; the signature and all the other content will be added as a new revision thus not invalidating existing signature&lt;/param&gt;
        /// &lt;param name=&quot;reason&quot;&gt;Reason field of signature&lt;/param&gt;
        /// &lt;param name=&quot;location&quot;&gt;Location field of signature&lt;/param&gt;
        /// &lt;param name=&quot;contact&quot;&gt;Contact field of signature&lt;/param&gt;
        /// &lt;param name=&quot;tsaClientUrl&quot;&gt;Timestamp server URL&lt;/param&gt;
        /// &lt;param name=&quot;tsaClientLogin&quot;&gt;Login user for timestamp server (BASIC authentication)&lt;/param&gt;
        /// &lt;param name=&quot;tsaClientPwd&quot;&gt;Login password for timestamp server&lt;/param&gt;
        public static void SignPdf(X509Certificate2 certificate, Stream inputPdfStream, Stream outputPdfStream, bool append, string reason, string location, string contact, string tsaClientUrl, string tsaClientLogin, string tsaClientPwd)
        {
            // Building certificate chain for the OCSP verification
            X509Chain ch = new X509Chain();
            ch.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
            ch.Build(certificate);

            Org.BouncyCastle.X509.X509Certificate[] chain = new Org.BouncyCastle.X509.X509Certificate[ch.ChainElements.Count];
            Org.BouncyCastle.X509.X509CertificateParser cp = new Org.BouncyCastle.X509.X509CertificateParser();
            int i = 0;

            foreach (X509ChainElement element in ch.ChainElements)
            {
                Org.BouncyCastle.X509.X509Certificate chainElement = cp.ReadCertificate(element.Certificate.RawData);
                chain[i] = chainElement;
                i++;
            }

            //Org.BouncyCastle.X509.X509CertificateParser cp = new Org.BouncyCastle.X509.X509CertificateParser();
            //Org.BouncyCastle.X509.X509Certificate[] chain = new Org.BouncyCastle.X509.X509Certificate[] { cp.ReadCertificate(certificate.RawData) };

            PdfReader reader = new PdfReader(inputPdfStream);
            PdfStamper st = PdfStamper.CreateSignature(reader, outputPdfStream, '&#092;&#048;', null, append);
            PdfSignatureAppearance sap = st.SignatureAppearance;

            sap.SetCrypto(null, chain, null, PdfSignatureAppearance.SELF_SIGNED);

            sap.Reason = reason;
            sap.Contact = contact;
            sap.Location = location;

            sap.SetVisibleSignature(new iTextSharp.text.Rectangle(50, 50, 200, 100), 1, null);

            PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKLITE, new PdfName(&quot;adbe.pkcs7.detached&quot;));
            dic.Reason = sap.Reason;
            dic.Location = sap.Location;
            dic.Contact = sap.Contact;
            dic.Date = new PdfDate(sap.SignDate);
            sap.CryptoDictionary = dic;

            int contentEstimated = 15000;

            Dictionary&lt;PdfName, int&gt; exc = new Dictionary&lt;PdfName, int&gt;();
            exc[PdfName.CONTENTS] = contentEstimated * 2 + 2;
            sap.PreClose(exc);

            PdfPKCS7 sgn = new PdfPKCS7(null, chain, null, &quot;SHA1&quot;, false);
            IDigest messageDigest = DigestUtilities.GetDigest(&quot;SHA1&quot;);
            Stream data = sap.RangeStream;
            byte[] buf = new byte[8192];
            int n;
            while ((n = data.Read(buf, 0, buf.Length)) &gt; 0)
            {
                messageDigest.BlockUpdate(buf, 0, n);
            }
            byte[] hash = new byte[messageDigest.GetDigestSize()];
            messageDigest.DoFinal(hash, 0);
            DateTime cal = DateTime.Now;
            byte[] ocsp = null;
            if (chain.Length &gt;= 2)
            {
                String url = PdfPKCS7.GetOCSPURL(chain[0]);
                if (url != null &amp;&amp; url.Length &gt; 0)
                    ocsp = new OcspClientBouncyCastle(chain[0], chain[1], url).GetEncoded();

                //File.WriteAllBytes(@&quot;..\..\..\ocsp.pdf&quot;, ocsp);
            }
            byte[] sh = sgn.GetAuthenticatedAttributeBytes(hash, cal, ocsp);

            // SHA1withRSA calculated by CAPI
            byte[] signedHashValue = SignSHA1withRSA(certificate, sh);
            sgn.SetExternalDigest(signedHashValue, hash, &quot;RSA&quot;);

            byte[] paddedSig = new byte[contentEstimated];

            if (!string.IsNullOrEmpty(tsaClientUrl))
            {
                TSAClientBouncyCastle tsc = new TSAClientBouncyCastle(tsaClientUrl, tsaClientLogin, tsaClientPwd);
                byte[] encodedSigTsa = sgn.GetEncodedPKCS7(hash, cal, tsc, ocsp);
                System.Array.Copy(encodedSigTsa, 0, paddedSig, 0, encodedSigTsa.Length);
                if (contentEstimated + 2 &lt; encodedSigTsa.Length)
                    throw new ApplicationException(&quot;Not enough space for signature&quot;);
            }
            else
            {
                byte[] encodedSig = sgn.GetEncodedPKCS7(hash, cal, null, ocsp);
                System.Array.Copy(encodedSig, 0, paddedSig, 0, encodedSig.Length);
                if (contentEstimated + 2 &lt; encodedSig.Length)
                    throw new ApplicationException(&quot;Not enough space for signature&quot;);
            }

            PdfDictionary dic2 = new PdfDictionary();
            dic2.Put(PdfName.CONTENTS, new PdfString(paddedSig).SetHexWriting(true));
            sap.Close(dic2);
        }

        public static byte[] SignSHA1withRSA(X509Certificate2 certificate, byte[] input)
        {
            const Int32 CRYPT_ACQUIRE_USE_PROV_INFO_FLAG = 0x00000002;
            const Int32 CRYPT_ACQUIRE_COMPARE_KEY_FLAG = 0x00000004;

            IntPtr privateKeyHandle = IntPtr.Zero;
            bool isCallerNeedFreeKeyHandle = false;
            IntPtr hashHandle = IntPtr.Zero;
            byte[] result = null;

            try
            {
                IntPtr cardHandle = certificate.Handle;
                Int32 pdwKeySpec = Crypto.AT_SIGNATURE;

                if (!Crypto.CryptAcquireCertificatePrivateKey(cardHandle, CRYPT_ACQUIRE_USE_PROV_INFO_FLAG |
                                                     CRYPT_ACQUIRE_COMPARE_KEY_FLAG, IntPtr.Zero, ref privateKeyHandle, ref pdwKeySpec, ref isCallerNeedFreeKeyHandle))
                {
                    throw new CryptographicException(Marshal.GetLastWin32Error());
                }

                if (!Crypto.CryptCreateHash(privateKeyHandle, Crypto.CALG_SHA1, IntPtr.Zero, 0, ref hashHandle))
                {
                    throw new CryptographicException(Marshal.GetLastWin32Error());
                }

                MemoryStream streamInput = new MemoryStream(input);
                byte[] buffer = new byte[4096];

                while (true)
                {
                    int read = streamInput.Read(buffer, 0, buffer.Length);

                    if (read == 0)
                        break;

                    if (!Crypto.CryptHashData(hashHandle, buffer, read, 0))
                    {
                        throw new CryptographicException(Marshal.GetLastWin32Error());
                    }
                }

                int pwdSigLen = 0;
                if (!Crypto.CryptSignHash(hashHandle, pdwKeySpec, null, 0, null, ref pwdSigLen))
                {
                    throw new CryptographicException(Marshal.GetLastWin32Error());
                }

                result = new byte[pwdSigLen];

                if (!Crypto.CryptSignHash(hashHandle, pdwKeySpec, null, 0, result, ref pwdSigLen))
                {
                    throw new CryptographicException(Marshal.GetLastWin32Error());
                }

                // CAPI generated hash has a different indian order
                Array.Reverse(result);
            }
            finally
            {

                if (hashHandle != IntPtr.Zero)
                {
                    if (!Crypto.CryptDestroyHash(hashHandle))
                    {
                        throw new CryptographicException(Marshal.GetLastWin32Error());
                    }
                }

                if (isCallerNeedFreeKeyHandle &amp;&amp; privateKeyHandle != IntPtr.Zero)
                {
                    if (!Crypto.CryptReleaseContext(privateKeyHandle, 0))
                    {
                        throw new CryptographicException(Marshal.GetLastWin32Error());
                    }
                }
            }

            return result;

        }

        public static X509Certificate2 SelectCertificate()
        {
            X509Store st = new X509Store(StoreName.My, StoreLocation.CurrentUser);
            st.Open(OpenFlags.ReadOnly);
            X509Certificate2Collection col = st.Certificates.Find(X509FindType.FindByKeyUsage, X509KeyUsageFlags.NonRepudiation, true);

            X509Certificate2 card = null;
            X509Certificate2Collection sel = X509Certificate2UI.SelectFromCollection(col, &quot;Certificates&quot;, &quot;Select one to sign&quot;, X509SelectionFlag.SingleSelection);
            if (sel.Count &gt; 0)
            {
                X509Certificate2Enumerator en = sel.GetEnumerator();
                en.MoveNext();
                card = en.Current;
            }
            st.Close();
            return card;
        }
    }
}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gubus2.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gubus2.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gubus2.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gubus2.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gubus2.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gubus2.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gubus2.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gubus2.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gubus2.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gubus2.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gubus2.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gubus2.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gubus2.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gubus2.wordpress.com/219/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=219&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gubus2.wordpress.com/2010/12/25/how-to-sign-with-a-timestamp-and-ocsp-in-c-smart-card-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/395eea308be2d771d18b9305b854e95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gubus</media:title>
		</media:content>
	</item>
		<item>
		<title>Elektronikus aláírás készítése PDF állományra smart card támogatással .NET alatt</title>
		<link>http://gubus2.wordpress.com/2010/09/01/elektronikus-alairas-keszitese-pdf-allomanyra-smart-card-tamogatassal-net-alatt/</link>
		<comments>http://gubus2.wordpress.com/2010/09/01/elektronikus-alairas-keszitese-pdf-allomanyra-smart-card-tamogatassal-net-alatt/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 21:56:30 +0000</pubDate>
		<dc:creator>gubus</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[itext pdf]]></category>

		<guid isPermaLink="false">http://gubus2.wordpress.com/?p=201</guid>
		<description><![CDATA[Update 2010. 11. 27. &#8211; A SignPdf() hívás elején nem volt helyes a tanúsítványlánc felépítése, ami az &#8220;if (chain.Length &#62;= 2)&#8221; sornál levő OCSP ellenőrzés működéséhez kell. A PDF állományok elektronikusan alárhatóak, melyet .NET platformon az iTextSharp (http://sourceforge.net/projects/itextsharp/files/) osztálykönyvtárral lehet elvégezni. Az osztálykönyvtárhoz vannak példakódok a http://itextpdf.sourceforge.net/howtosign.html címen, egész jó tutorial-ok, vagy példaalkalmazások érhetőek el: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=201&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Update 2010. 11. 27. &#8211; A SignPdf() hívás elején nem volt helyes a tanúsítványlánc felépítése, ami az &#8220;if (chain.Length &gt;= 2)&#8221; sornál levő OCSP ellenőrzés működéséhez kell.</p>
<p>A PDF állományok elektronikusan alárhatóak, melyet .NET platformon az iTextSharp (http://sourceforge.net/projects/itextsharp/files/) osztálykönyvtárral lehet elvégezni.<br />
Az osztálykönyvtárhoz vannak példakódok a http://itextpdf.sourceforge.net/howtosign.html címen, egész jó tutorial-ok, vagy példaalkalmazások érhetőek el:</p>
<p>http://isafepdf.codeplex.com/</p>
<p>http://www.codeproject.com/KB/security/isafepdf.aspx?display=Print</p>
<p>Az aláírás mellett még az is szükséges, hogy az aláírásra időpecsét kerüljön, ugyanis ha a tanúsítvány lejár, vagy visszavonásra kerül, és ha nem állapítható meg hitelesen az aláírás időpontja, akkor nem lehet bizonyítani, hogy az elromlás előtt lett még az aláírás elkészítve. A fentiek miatt kell egy aláírói tanúsítványra az felhasználónak, és szükséges egy időpecsét szerver elérés is (előfizetés).</p>
<p>Ha felhasználó minősített elektronikus aláírást szeretne, akkor a tanúsítványát egy smard card kártyán kell, hogy tárolja. A kártya fontos tulajdonsága, hogy a tanúsítvány privát kulcsát nem lehet kiolvasni róla, csak meg lehet kérni a kártyát, hogy a kért kriptográfiai műveletet végezze el, és az eredményt adja vissza. A kriptográfiai API-knak van egy hagyomános működési módjuk is: ilyenkor az API a tanúsítvány privát kulcsát kiolvassa, és közvetlenül a kulcs felhasználásával számolja ki az eredményt.</p>
<p>A kártyáknak kétféle API-juk van:<br />
- PKCS #11<br />
- Microsoft™ CryptoAPI &#8211; gyakorlatilag egy Windows drivert jelent, segítségével a kártyára tett X509-es tanúsítványok egy az egyben megjelennek a Windows tanúsítványtárában, és így .NET-ből is könnyen elérhetőek.</p>
<p>A látott iTextSharp-os aláírást készítő példakódoknak két típusa van: az időpecsét nélküli, és időpecsétes.</p>
<p>1. Időpecsét nélküli, de smart card támogatással.<br />
How to sign with a smartcard using an external signature dictionary with iTextSharp and .NET 2.0</p>
<p>http://itextpdf.sourceforge.net/howtosign.html#signextitextsharp2</p>
<p>Ez a verzió a .NET SignedCms osztályát használja fel az aláírásra, mely egy PKCS#7  formátumú adatcsomagot ad vissza. A SignedCms kezeli azt az esetet is, ha a tanúsítvány kártyán van.</p>
<p>2. Időpecsétes, de smart card támogatás nélkül.<br />
How to sign with a timestamp and OCSP in C#</p>
<p>http://itextpdf.sourceforge.net/howtosign.html#signtsocspcs</p>
<p>Aláírás készítése időpecséttel. Itt bonyolultabb a működés: mivel a PKCS#7 csomagba még bele kell tenni az időpecsétre vonatkozó adatokat, ezért az iTextSharp mellé tett Bouncy Castle Crypto API (http://www.bouncycastle.org/) kézzel állítja elő az aláírás HASH-t, és rakja össze a PKCS#7 üzenetet. A Bouncy Castle viszont csak a privát kulcs birtokában tud dolgozni, ezért kártyán tárolt tanúsítvánnyal _nem_ működik a kód.</p>
<p>Első próbálkozásként megpróbáltam a .NET RSACryptoServiceProvider osztályával előállítani a SHA1withRSA aláírást:</p>
<pre class="brush: csharp;">
X509Certificate2 card = GetCertificate();
RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)card.PrivateKey;
byte[] signedHashValue1 = rsa.SignData(documentHash, new SHA1Managed());
</pre>
<p>Sajnos nem működik a kártyával, a card.PrivateKey -&gt; RSACryptoServiceProvider konverzió elszáll:</p>
<pre>
System.Security.Cryptography.CryptographicException: Bad Key.
at System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr)
at System.Security.Cryptography.Utils._GetKeyParameter(SafeKeyHandle hKey, UInt32 paramID)
at System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle&amp; safeProvHandle, SafeKeyHandle&amp; safeKeyHandle)
at System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()
at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters, Boolean useDefaultKeySize)
at System.Security.Cryptography.RSACryptoServiceProvider..ctor(CspParameters parameters)
at System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()
</pre>
<p>A card.PrivateKey -&gt; RSACryptoServiceProvider konverzióra van elvileg egy támogatott módszer:</p>
<pre class="brush: csharp;">
/// &lt;summary&gt;
/// private static RSACryptoServiceProvider PrivateKey(String providerName, String keyContainerName, KeyNumber keytype)
/// String providerName: &quot;Microsoft Base Smart Card Crypto Provider&quot; if your CSP implement a mini driver (Card Modules)
/// String keyContainerName: &quot;DS0&quot; for smart card Infocert type CNS 1204XXXX csp KeyContainerName first Digitale Signature Key Container
/// KeyNumber keytype: KeyNumber.Signature
/// &lt;/summary&gt;
private static RSACryptoServiceProvider PrivateKey(String providerName, String keyContainerName, KeyNumber keytype)
{
CspParameters csparms = new CspParameters();
csparms.ProviderName = providerName; // &quot;Microsoft Base Smart Card Crypto Provider&quot;;
csparms.KeyContainerName = keyContainerName; // &quot;DS0&quot;;
csparms.KeyNumber = (int)keytype;
csparms.ProviderType = 1;
csparms.Flags = CspProviderFlags.UseUserProtectedKey; // not sure you need this!
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(csparms);
return rsa;
}

certSigner.PrivateKey = PrivateKey(providerName, keyContainerName, KeyNumber.Signature);
</pre>
<p>De nem sikerült sajnos behergelni, meg az se szép benne, hogy nem általános a módszer, hanem a providerName, keyContainerName paramétereket kell hajkurászni (ami meg kártyafüggő).</p>
<p>Végül Windows CryptoAPI hívásokkal sikerült az SHA1withRSA aláírást előállítani úgy, hogy támogatja a kártyán levő tanúsítványt is.</p>
<p>A CryptoAPI hívásoknál felhasználtam Alejandro Campos Magencio által készített pinvoke segédosztályt is:</p>
<p>http://blogs.msdn.com/b/alejacma/archive/2007/11/23/p-invoking-cryptoapi-in-net-c-version.aspx</p>
<p>Íme a végeredmény:</p>
<pre class="brush: csharp;">

using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using iTextSharp.text.pdf;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Security;

namespace PdfSignerTest
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine(&quot;Start&quot;);

                string inputFileName = @&quot;..\..\..\Report.pdf&quot;;
                string outputFileName = @&quot;..\..\..\Signed.pdf&quot;;
                string timeStampUrl = &quot;http://www.xxxx.com/timestamp.cgi&quot;;

                using (FileStream inputPdfStream = new FileStream(inputFileName, FileMode.Open, FileAccess.Read))
                {
                    using (FileStream outputPdfStream = new FileStream(outputFileName, FileMode.Create, FileAccess.Write))
                    {
                        X509Certificate2 card = SelectCertificate();

                        SignPdf(card, inputPdfStream, outputPdfStream, false, &quot;Test Reason&quot;, &quot;Test Location&quot;, &quot;Test Contact&quot;, timeStampUrl, &quot;teszt&quot;, &quot;teszt&quot;);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                Console.WriteLine(&quot;Done.&quot;);
                Console.ReadLine();
            }
        }

        /// &lt;summary&gt;
        ///
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;certificate&quot;&gt;smart card certificate&lt;/param&gt;
        /// &lt;param name=&quot;inputPdfStream&quot;&gt;input PDF&lt;/param&gt;
        /// &lt;param name=&quot;outputPdfStream&quot;&gt;output PDF (signed)&lt;/param&gt;
        /// &lt;param name=&quot;append&quot;&gt;append if &lt;CODE&gt;true&lt;/CODE&gt; the signature and all the other content will be added as a new revision thus not invalidating existing signature&lt;/param&gt;
        /// &lt;param name=&quot;reason&quot;&gt;Reason field of signature&lt;/param&gt;
        /// &lt;param name=&quot;location&quot;&gt;Location field of signature&lt;/param&gt;
        /// &lt;param name=&quot;contact&quot;&gt;Contact field of signature&lt;/param&gt;
        /// &lt;param name=&quot;tsaClientUrl&quot;&gt;Timestamp server URL&lt;/param&gt;
        /// &lt;param name=&quot;tsaClientLogin&quot;&gt;Login user for timestamp server (BASIC authentication)&lt;/param&gt;
        /// &lt;param name=&quot;tsaClientPwd&quot;&gt;Login password for timestamp server&lt;/param&gt;
        public static void SignPdf(X509Certificate2 certificate, Stream inputPdfStream, Stream outputPdfStream, bool append, string reason, string location, string contact, string tsaClientUrl, string tsaClientLogin, string tsaClientPwd)
        {
            // Building certificate chain for the OCSP verification
            X509Chain ch = new X509Chain();
            ch.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
            ch.Build(certificate);

            Org.BouncyCastle.X509.X509Certificate[] chain = new Org.BouncyCastle.X509.X509Certificate[ch.ChainElements.Count];
            Org.BouncyCastle.X509.X509CertificateParser cp = new Org.BouncyCastle.X509.X509CertificateParser();
            int i = 0;

            foreach (X509ChainElement element in ch.ChainElements)
            {
                Org.BouncyCastle.X509.X509Certificate chainElement = cp.ReadCertificate(element.Certificate.RawData);
                chain[i] = chainElement;
                i++;
            }

            //Org.BouncyCastle.X509.X509CertificateParser cp = new Org.BouncyCastle.X509.X509CertificateParser();
            //Org.BouncyCastle.X509.X509Certificate[] chain = new Org.BouncyCastle.X509.X509Certificate[] { cp.ReadCertificate(certificate.RawData) };

            PdfReader reader = new PdfReader(inputPdfStream);
            PdfStamper st = PdfStamper.CreateSignature(reader, outputPdfStream, '&#092;&#048;', null, append);
            PdfSignatureAppearance sap = st.SignatureAppearance;

            sap.SetCrypto(null, chain, null, PdfSignatureAppearance.SELF_SIGNED);

            sap.Reason = reason;
            sap.Contact = contact;
            sap.Location = location;

            sap.SetVisibleSignature(new iTextSharp.text.Rectangle(50, 50, 200, 100), 1, null);

            PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKLITE, new PdfName(&quot;adbe.pkcs7.detached&quot;));
            dic.Reason = sap.Reason;
            dic.Location = sap.Location;
            dic.Contact = sap.Contact;
            dic.Date = new PdfDate(sap.SignDate);
            sap.CryptoDictionary = dic;

            int contentEstimated = 15000;

            Dictionary&lt;PdfName, int&gt; exc = new Dictionary&lt;PdfName, int&gt;();
            exc[PdfName.CONTENTS] = contentEstimated * 2 + 2;
            sap.PreClose(exc);

            PdfPKCS7 sgn = new PdfPKCS7(null, chain, null, &quot;SHA1&quot;, false);
            IDigest messageDigest = DigestUtilities.GetDigest(&quot;SHA1&quot;);
            Stream data = sap.RangeStream;
            byte[] buf = new byte[8192];
            int n;
            while ((n = data.Read(buf, 0, buf.Length)) &gt; 0)
            {
                messageDigest.BlockUpdate(buf, 0, n);
            }
            byte[] hash = new byte[messageDigest.GetDigestSize()];
            messageDigest.DoFinal(hash, 0);
            DateTime cal = DateTime.Now;
            byte[] ocsp = null;
            if (chain.Length &gt;= 2)
            {
                String url = PdfPKCS7.GetOCSPURL(chain[0]);
                if (url != null &amp;&amp; url.Length &gt; 0)
                    ocsp = new OcspClientBouncyCastle(chain[0], chain[1], url).GetEncoded();

                //File.WriteAllBytes(@&quot;..\..\..\ocsp.pdf&quot;, ocsp);
            }
            byte[] sh = sgn.GetAuthenticatedAttributeBytes(hash, cal, ocsp);

            // SHA1withRSA calculated by CAPI
            byte[] signedHashValue = SignSHA1withRSA(certificate, sh);
            sgn.SetExternalDigest(signedHashValue, hash, &quot;RSA&quot;);

            byte[] paddedSig = new byte[contentEstimated];

            if (!string.IsNullOrEmpty(tsaClientUrl))
            {
                TSAClientBouncyCastle tsc = new TSAClientBouncyCastle(tsaClientUrl, tsaClientLogin, tsaClientPwd);
                byte[] encodedSigTsa = sgn.GetEncodedPKCS7(hash, cal, tsc, ocsp);
                System.Array.Copy(encodedSigTsa, 0, paddedSig, 0, encodedSigTsa.Length);
                if (contentEstimated + 2 &lt; encodedSigTsa.Length)
                    throw new ApplicationException(&quot;Not enough space for signature&quot;);
            }
            else
            {
                byte[] encodedSig = sgn.GetEncodedPKCS7(hash, cal, null, ocsp);
                System.Array.Copy(encodedSig, 0, paddedSig, 0, encodedSig.Length);
                if (contentEstimated + 2 &lt; encodedSig.Length)
                    throw new ApplicationException(&quot;Not enough space for signature&quot;);
            }

            PdfDictionary dic2 = new PdfDictionary();
            dic2.Put(PdfName.CONTENTS, new PdfString(paddedSig).SetHexWriting(true));
            sap.Close(dic2);
        }

        public static byte[] SignSHA1withRSA(X509Certificate2 certificate, byte[] input)
        {
            const Int32 CRYPT_ACQUIRE_USE_PROV_INFO_FLAG = 0x00000002;
            const Int32 CRYPT_ACQUIRE_COMPARE_KEY_FLAG = 0x00000004;

            IntPtr privateKeyHandle = IntPtr.Zero;
            bool isCallerNeedFreeKeyHandle = false;
            IntPtr hashHandle = IntPtr.Zero;
            byte[] result = null;

            try
            {
                IntPtr cardHandle = certificate.Handle;
                Int32 pdwKeySpec = Crypto.AT_SIGNATURE;

                if (!Crypto.CryptAcquireCertificatePrivateKey(cardHandle, CRYPT_ACQUIRE_USE_PROV_INFO_FLAG |
                                                     CRYPT_ACQUIRE_COMPARE_KEY_FLAG, IntPtr.Zero, ref privateKeyHandle, ref pdwKeySpec, ref isCallerNeedFreeKeyHandle))
                {
                    throw new CryptographicException(Marshal.GetLastWin32Error());
                }

                if (!Crypto.CryptCreateHash(privateKeyHandle, Crypto.CALG_SHA1, IntPtr.Zero, 0, ref hashHandle))
                {
                    throw new CryptographicException(Marshal.GetLastWin32Error());
                }

                MemoryStream streamInput = new MemoryStream(input);
                byte[] buffer = new byte[4096];

                while (true)
                {
                    int read = streamInput.Read(buffer, 0, buffer.Length);

                    if (read == 0)
                        break;

                    if (!Crypto.CryptHashData(hashHandle, buffer, read, 0))
                    {
                        throw new CryptographicException(Marshal.GetLastWin32Error());
                    }
                }

                int pwdSigLen = 0;
                if (!Crypto.CryptSignHash(hashHandle, pdwKeySpec, null, 0, null, ref pwdSigLen))
                {
                    throw new CryptographicException(Marshal.GetLastWin32Error());
                }

                result = new byte[pwdSigLen];

                if (!Crypto.CryptSignHash(hashHandle, pdwKeySpec, null, 0, result, ref pwdSigLen))
                {
                    throw new CryptographicException(Marshal.GetLastWin32Error());
                }

                // CAPI generated hash has a different indian order
                Array.Reverse(result);
            }
            finally
            {

                if (hashHandle != IntPtr.Zero)
                {
                    if (!Crypto.CryptDestroyHash(hashHandle))
                    {
                        throw new CryptographicException(Marshal.GetLastWin32Error());
                    }
                }

                if (isCallerNeedFreeKeyHandle &amp;&amp; privateKeyHandle != IntPtr.Zero)
                {
                    if (!Crypto.CryptReleaseContext(privateKeyHandle, 0))
                    {
                        throw new CryptographicException(Marshal.GetLastWin32Error());
                    }
                }
            }

            return result;

        }

        public static X509Certificate2 SelectCertificate()
        {
            X509Store st = new X509Store(StoreName.My, StoreLocation.CurrentUser);
            st.Open(OpenFlags.ReadOnly);
            X509Certificate2Collection col = st.Certificates.Find(X509FindType.FindByKeyUsage, X509KeyUsageFlags.NonRepudiation, true);

            X509Certificate2 card = null;
            X509Certificate2Collection sel = X509Certificate2UI.SelectFromCollection(col, &quot;Certificates&quot;, &quot;Select one to sign&quot;, X509SelectionFlag.SingleSelection);
            if (sel.Count &gt; 0)
            {
                X509Certificate2Enumerator en = sel.GetEnumerator();
                en.MoveNext();
                card = en.Current;
            }
            st.Close();
            return card;
        }
    }
}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gubus2.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gubus2.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gubus2.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gubus2.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gubus2.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gubus2.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gubus2.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gubus2.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gubus2.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gubus2.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gubus2.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gubus2.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gubus2.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gubus2.wordpress.com/201/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=201&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gubus2.wordpress.com/2010/09/01/elektronikus-alairas-keszitese-pdf-allomanyra-smart-card-tamogatassal-net-alatt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/395eea308be2d771d18b9305b854e95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gubus</media:title>
		</media:content>
	</item>
		<item>
		<title>TransactionScope + System.Data.SQLClient &#8211;  timeout bug</title>
		<link>http://gubus2.wordpress.com/2008/08/29/transactionscope-systemdatasqlclient-timeout-bug/</link>
		<comments>http://gubus2.wordpress.com/2008/08/29/transactionscope-systemdatasqlclient-timeout-bug/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 12:28:22 +0000</pubDate>
		<dc:creator>gubus</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://gubus2.wordpress.com/?p=198</guid>
		<description><![CDATA[Érdekes hibába futottam bele pár hete: Issue with System.Transactions, SqlConnection and Timeout How to Use System.Data with System.Transactions and Maintain Atomicity and Data Consistency Szituáció: Egy folyamat a new TransactionScope(..)- hívással megnyitja a tranzakciót, majd folyamat elkezdi a scope-on belül az SQL Server adatbázisokat matatni. Abban az esetben, ha a matatás folyamat lassú, és nem [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=198&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Érdekes hibába futottam bele pár hete:</p>
<p><a href="http://weblogs.asp.net/ryangaraygay/archive/2008/04/14/issue-with-system-transactions-sqlconnection-and-timeout.aspx">Issue with System.Transactions, SqlConnection and Timeout</a></p>
<p><a href="http://blogs.msdn.com/florinlazar/archive/2008/05/05/8460156.aspx">How to Use System.Data with System.Transactions and Maintain Atomicity and Data Consistency</a></p>
<p>Szituáció: Egy folyamat a new TransactionScope(..)- hívással megnyitja a tranzakciót, majd folyamat elkezdi a scope-on belül az SQL Server adatbázisokat matatni.</p>
<p>Abban az esetben, ha a matatás folyamat lassú, és nem jut el tranzakció timeout időn belül a TransactionScope <span> </span>Complete() hívásáig, akkor:</p>
<p>- a timeout leteltekor az SqlConnection – transaction kötés megszűnik,</p>
<p>- a kapcsolat tranzakció nélkül lóg a levegőben, auto commit módban került, vagyis ezután minden rajta keresztül végzett művelet commitolva <span> </span>lesz,</p>
<p>- a matatás végeztekor a folyamat meghívja a TransactionScope <span> </span>Complete() hívást, ami Exception-nel jelzi, hogy timeout van, és visszavonja timeout <strong>letelte előtt </strong>végzett műveleteket.</p>
<p>Következmény: a timeout után végzett módosítások nem kerülnek visszavonásra.</p>
<p>A hibát észrevették, javították, de úgy, hogy a javított viselkedést külön kell aktiválni a connection string-ben megadott <strong>transaction binding=explicit Unbind;</strong> paraméterrel.</p>
<p>Mely CLR verziókban támogatott:</p>
<table border="3">
<tbody>
<tr>
<td>Version</td>
<td>transaction binding supported?</td>
<td>Comment</td>
</tr>
<tr>
<td>2.0.50727.42</td>
<td>-</td>
<td>RTM</td>
</tr>
<tr>
<td>2.0.50727.832</td>
<td>-</td>
<td>KB928365 – (RTM után, de még SP1 előtt)</td>
</tr>
<tr>
<td>2.0.50727.1433</td>
<td>+</td>
<td>.NET 2.0 SP1</td>
</tr>
<tr>
<td>2.0.50727.3053</td>
<td>+</td>
<td>.NET 2.0 SP2</td>
</tr>
</tbody>
</table>
<p>Illetve <a href="http://blogs.msdn.com/florinlazar/default.aspx">Florin Lazar</a> szerint:</p>
<p><span>&#8220;Hopefully, the default behavior will change to explicit unbind in the future releases (non-SP) of .Net Framework.&#8221;</span></p>
<p>Mi a tranzakció timeout értéke?</p>
<p>A Machine.Config-ban a configuration/system.transactions/machineSettings elemnél a maxTimeout a gépen belül beállítható max timeout-ot adja meg, ami alapesetben 10 perc.</p>
<p>Ezen belül mozoghat alkalmazásonként az App.Config-ban a configuration/system.transactions/defaultSettings elemnél a timeout paraméter, mely alapesetben 1 perc.</p>
<p>Tehát alapértelmezett esetben 1 perc .</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/gubus2.wordpress.com/198/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/gubus2.wordpress.com/198/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gubus2.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gubus2.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gubus2.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gubus2.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gubus2.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gubus2.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gubus2.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gubus2.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gubus2.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gubus2.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gubus2.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gubus2.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gubus2.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gubus2.wordpress.com/198/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=198&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gubus2.wordpress.com/2008/08/29/transactionscope-systemdatasqlclient-timeout-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/395eea308be2d771d18b9305b854e95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gubus</media:title>
		</media:content>
	</item>
		<item>
		<title>links for 2007-10-16</title>
		<link>http://gubus2.wordpress.com/2007/10/16/links-for-2007-10-16/</link>
		<comments>http://gubus2.wordpress.com/2007/10/16/links-for-2007-10-16/#comments</comments>
		<pubDate>Tue, 16 Oct 2007 06:29:01 +0000</pubDate>
		<dc:creator>gubus</dc:creator>
				<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://gubus2.wordpress.com/2007/10/16/links-for-2007-10-16/</guid>
		<description><![CDATA[Application Pool Recycle Utility for SharePoint Developers System Tray utility for providing quick access to common IIS tasks. It may also be useful to others working with IIS. It may also be useful to others working with IIS. In essence, it enumerates the app pools on your box and lets you right click &#8216;em to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=190&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<ul class="delicious">
<li>
<div class="delicious-link"><a href="http://www.harbar.net/articles/APM.aspx">Application Pool Recycle Utility for SharePoint Developers</a></div>
<div class="delicious-extended">System Tray utility for providing quick access to common IIS tasks. It may also be useful to others working with IIS. It may also be useful to others working with IIS. In essence, it enumerates the app pools on your box and lets you right click &#8216;em to bou</div>
<div class="delicious-tags">(tags: <a href="http://del.icio.us/gnagypal/iis">iis</a> <a href="http://del.icio.us/gnagypal/tools">tools</a> <a href="http://del.icio.us/gnagypal/tips">tips</a> <a href="http://del.icio.us/gnagypal/application">application</a> <a href="http://del.icio.us/gnagypal/pool">pool</a>)</div>
</li>
<li>
<div class="delicious-link"><a href="http://blogs.msdn.com/joelo/archive/2007/07/16/iisreset-is-bruteforce-there-are-civilized-alternatives-iisapp-vbs.aspx">Joel Oleson&#8217;s SharePoint Land : IISReset is bruteforce, there are civilized alternatives (IISApp.vbs)</a></div>
<div class="delicious-extended">Application Pool reset: cscript c:\windows\system32\iisapp.vbs /a &#8220;%SharePointAppPool%&#8221; /r</div>
<div class="delicious-tags">(tags: <a href="http://del.icio.us/gnagypal/iis">iis</a> <a href="http://del.icio.us/gnagypal/tips">tips</a> <a href="http://del.icio.us/gnagypal/application">application</a> <a href="http://del.icio.us/gnagypal/pool">pool</a>)</div>
</li>
<li>
<div class="delicious-link"><a href="http://geekswithblogs.net/scottkuhl/archive/2007/04/09/111195.aspx">Visual Studio 2005 Collapse All Macro</a></div>
<div class="delicious-extended">Javítás:<br />
If innerItem.UIHierarchyItems.Count &gt; 0 And innerItem.UIHierarchyItems.Expanded Then</div>
<div class="delicious-tags">(tags: <a href="http://del.icio.us/gnagypal/visualstudio">visualstudio</a> <a href="http://del.icio.us/gnagypal/macro">macro</a>)</div>
</li>
<li>
<div class="delicious-link"><a href="http://blog.solanite.com/keith/WLA/default.aspx">Windows Live ID Authentication for SharePoint v1.0</a></div>
<div class="delicious-extended">Features: Windows Live ID Authentication / Ability to lock users / &#8220;Authenticated Live Users&#8221; role which works like NT_AUTHORITY\Authenticated Users</div>
<div class="delicious-tags">(tags: <a href="http://del.icio.us/gnagypal/sharepoint">sharepoint</a> <a href="http://del.icio.us/gnagypal/passport">passport</a> <a href="http://del.icio.us/gnagypal/live">live</a> <a href="http://del.icio.us/gnagypal/authentication">authentication</a>)</div>
</li>
</ul>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/gubus2.wordpress.com/190/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/gubus2.wordpress.com/190/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gubus2.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gubus2.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gubus2.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gubus2.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gubus2.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gubus2.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gubus2.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gubus2.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gubus2.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gubus2.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gubus2.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gubus2.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gubus2.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gubus2.wordpress.com/190/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=190&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gubus2.wordpress.com/2007/10/16/links-for-2007-10-16/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/395eea308be2d771d18b9305b854e95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gubus</media:title>
		</media:content>
	</item>
		<item>
		<title>SWA + .NET + interoperabilitás</title>
		<link>http://gubus2.wordpress.com/2007/06/09/swa-net-interoperabilitas/</link>
		<comments>http://gubus2.wordpress.com/2007/06/09/swa-net-interoperabilitas/#comments</comments>
		<pubDate>Sat, 09 Jun 2007 21:10:16 +0000</pubDate>
		<dc:creator>gubus</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://gubus2.wordpress.com/2007/06/09/swa-net-interoperabilitas/</guid>
		<description><![CDATA[Munkahelyemen sikerült kifogni egy érdekes interfész csatlakozást. Hivatali kapu a neve, a cucc Java-ban készült, AXIS 1 könyvtár felhasználásával, SOAP over HTTP; van egy szerver, oda kell a kéréseket küldeni HTTP-n. Van WSDL, ami egyáltalán nem használható, de legtöbb funkcióhoz legalább van XSD. A problémás a csatolt dokumentumok kezelése: az űrlapok letöltésekor, és a válaszüzenetek küldésekor csatolt [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=183&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Munkahelyemen sikerült kifogni egy érdekes interfész csatlakozást. Hivatali kapu a neve, a cucc Java-ban készült, AXIS 1 könyvtár felhasználásával, SOAP over HTTP; van egy szerver, oda kell a kéréseket küldeni HTTP-n. Van WSDL, ami egyáltalán nem használható, de legtöbb funkcióhoz legalább van XSD.</p>
<p>A problémás a csatolt dokumentumok kezelése: az űrlapok letöltésekor, és a válaszüzenetek küldésekor csatolt doksiként megy a fájl a SOAP boríték mellett. A  használt mód: <a href="http://www.w3.org/TR/SOAP-attachments">http://www.w3.org/TR/SOAP-attachments</a> , vagyis az SWA. Látni, hogy nem W3C hivatalos ajánlás, csak Note szinten van jegyezve.</p>
<p>MS (.NET) oldalon csak a <a href="http://xml.coverpages.org/dime.html">DIME</a> (WSE2), <a href="http://www.w3.org/TR/soap12-mtom/">MTOM</a> (WSE3, WCF) módszerek van támogatva csatolás kezelésre, az SWA nincs implementálva. MTOM a hivatalos W3C szabvány, DIME az MS saját megoldása, az SWA pedig nem MS környezetben terjedt el.</p>
<p>Az SWA nem bonyolult:</p>
<p>&#8220;The specification combines specific usage of the Multipart/Related MIME media type (<a href="http://www.w3.org/TR/SOAP-attachments#MultipartRelated"><font color="#0000cc">RFC 2387</font></a>) and the URI schemes discussed in <a href="http://www.w3.org/TR/SOAP-attachments#CID"><font color="#0000cc">RFC 2111</font></a> and <a href="http://www.w3.org/TR/SOAP-attachments#RFC2557"><font color="#0000cc">RFC2557</font></a> for referencing MIME parts.&#8221;</p>
<p>Letöltéskor A SOAP üzenet helyet egy MIME üzenetet kell parsolni, majd abból SOAP üzenetet és a csatolt fájlt kivenni, feltöltéskor pedig egy MIME  üzenetet kell a SOAP üzenetből és a fájlból előállítani.</p>
<p>MIME parsolásra és előállításra könyvtár: <a href="http://www.codeproject.com/csharp/mime_project.asp">CodeProject: Advanced MIME Parser/Creator/Editor</a></p>
<p>Legutolsó verziójának letöltése: <a href="http://www.lumisoft.ee/lsWWW/Download/Downloads/Net/">http://www.lumisoft.ee/lsWWW/Download/Downloads/Net/</a></p>
<p>A LumiSoft Net library elég sok dolgot tartalmaz:, pl.: pop3 client+server, imap client+server, smtp client+server, a help-je elég beszédes: <a href="http://www.lumisoft.ee/lsWWW/Download/Downloads/Net/Help/Index.html">http://www.lumisoft.ee/lsWWW/Download/Downloads/Net/Help/Index.html</a></p>
<p>Egyéb régi, de kapcsolódó cikkek:</p>
<p><a href="http://benjaminm.net/2004/02/02/FindingANETImplementationOfSOAPMessagesWithAttachments.aspx">Finding a .NET implementation of SOAP Messages with Attachments</a></p>
<p><a href="http://msdn2.microsoft.com/en-us/library/ms996462.aspx">Web Services, Opaque Data, and the Attachments Problem</a></p>
<p><a href="http://inetcom.hu/mick/publikaciok/">Mick Tech.Net Magazinban publikált MIME sorozata</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/gubus2.wordpress.com/183/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/gubus2.wordpress.com/183/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gubus2.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gubus2.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gubus2.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gubus2.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gubus2.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gubus2.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gubus2.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gubus2.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gubus2.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gubus2.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gubus2.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gubus2.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gubus2.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gubus2.wordpress.com/183/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=183&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gubus2.wordpress.com/2007/06/09/swa-net-interoperabilitas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/395eea308be2d771d18b9305b854e95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gubus</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET webszolgáltatás kliens és basic autentikáció</title>
		<link>http://gubus2.wordpress.com/2007/05/04/aspnet-webszolgaltatas-kliens-es-basic-autentikacio/</link>
		<comments>http://gubus2.wordpress.com/2007/05/04/aspnet-webszolgaltatas-kliens-es-basic-autentikacio/#comments</comments>
		<pubDate>Fri, 04 May 2007 14:12:06 +0000</pubDate>
		<dc:creator>gubus</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://gubus2.wordpress.com/2007/05/04/aspnet-webszolgaltatas-kliens-es-basic-autentikacio/</guid>
		<description><![CDATA[Hagyományos ASP.NET webszolgáltatás kliens proxy-t a SoapHttpClientProtocol osztályból leszármaztatva generálja le a .NET, aminek őse a WebClientProtocol. A WebClientProtocol rendelkezik egy PreAuthenticate tulajdonsággal, amit basic autentikációnál érdemes használni. Ha a PreAuthenticate = false (alapértelmezett), akkor minden webszolgáltatás hívás előtt egy egyeztetés zajlik a szerver és a kliens között az azonosítás kapcsán: a kliens autentikáció nélkül [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=176&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hagyományos ASP.NET webszolgáltatás kliens proxy-t a SoapHttpClientProtocol osztályból leszármaztatva generálja le a .NET, aminek őse a WebClientProtocol. A WebClientProtocol rendelkezik egy PreAuthenticate tulajdonsággal, amit basic autentikációnál érdemes használni.</p>
<p>Ha a PreAuthenticate = false (alapértelmezett), akkor minden webszolgáltatás hívás előtt egy egyeztetés zajlik a szerver és a kliens között az azonosítás kapcsán: a kliens autentikáció nélkül küld egy kérést, a szerver, ha kötelező az autentikáció, akkor egy &#8220;HTTP Error 401.2 &#8211; Unauthorized: Access is denied due to server configuration.&#8221; üzenettel jelzi, hogy ő mindenképpen azonosítani akarja a klienst. A kliens csak ekkor a válaszol a név-jelszó párossal az Authorization mezőben, vagyis minden egyes webszolgáltatás hívás két HTTP hívást fog eredményezni. Ethereal-lal, Packetyzer-rel monitorozva a hálózatot látszik szépen, hogy minden hívás előtt ott lesz egy 1800 byte-os IIS HTTP Error 401.2 hibalap.</p>
<p>Ha a PreAuthenticate = true, akkor csak a legelső hívásnál zajlik le az egyeztetés, a következőnél már nincs szükség rá. A gyakorlatban ez azt jelenti, hogy a kliens proxy objektumot nem szabad minden hívás előtt újra létrehozni, beállítani, hanem csak egyszer kell beállítani (és PreAuthenticate = true), majd utána a beállított objektumon kell hívogatni a szervert.</p>
<p>Ha legelső egyeztetést is meg akarjuk spórolni, akkor a generált proxy-n módosítani kell: a GetWebRequest() metódust felül kell írni, és be kell állítani az Authorization header értékét:<br />
<a href="http://mark.michaelis.net/Blog/CallingWebServicesUsingBasicAuthentication.aspx">Calling web services using basic authentication</a></p>
<p>A példában van egy hiba, a &#8220;Basic&#8221; + Convert.ToBase64String(credentialBuffer); helyett &#8220;Basic &#8221; + Convert.ToBase64String(credentialBuffer); kell.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/gubus2.wordpress.com/176/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/gubus2.wordpress.com/176/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gubus2.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gubus2.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gubus2.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gubus2.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gubus2.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gubus2.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gubus2.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gubus2.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gubus2.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gubus2.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gubus2.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gubus2.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gubus2.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gubus2.wordpress.com/176/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=176&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gubus2.wordpress.com/2007/05/04/aspnet-webszolgaltatas-kliens-es-basic-autentikacio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/395eea308be2d771d18b9305b854e95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gubus</media:title>
		</media:content>
	</item>
		<item>
		<title>Delphi kliens + ASP.NET 2.0 Webszolgáltatás</title>
		<link>http://gubus2.wordpress.com/2007/05/04/delphi-kliens-aspnet-20-webszolgaltatas/</link>
		<comments>http://gubus2.wordpress.com/2007/05/04/delphi-kliens-aspnet-20-webszolgaltatas/#comments</comments>
		<pubDate>Fri, 04 May 2007 14:11:03 +0000</pubDate>
		<dc:creator>gubus</dc:creator>
				<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://gubus2.wordpress.com/2007/05/04/delphi-kliens-aspnet-20-webszolgaltatas/</guid>
		<description><![CDATA[Az a jelenség, hogy a küldött paraméterek nem látszanak szerver oldalon, ugyanis a kliens RPC bindinget használja a szerver által kért Literal helyett. Ez azért van, mert Delphi kódgenerátora kihagyja a InvRegistry.RegisterInvokeOptions(TypeInfo(xxx), ioDocument);  sort a generált kódból, ezt kell betenni. Lásd: Consuming ASP.NET 2.0 Web Services in Delphi for Win32<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=177&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Az a jelenség, hogy a küldött paraméterek nem látszanak szerver oldalon, ugyanis a kliens RPC bindinget használja a szerver által kért Literal helyett.</p>
<p>Ez azért van, mert Delphi kódgenerátora kihagyja a</p>
<pre>InvRegistry.RegisterInvokeOptions(TypeInfo(xxx), ioDocument); </pre>
<p>sort a generált kódból, ezt kell betenni.</p>
<p>Lásd: <a href="http://www.bobswart.nl/weblog/Blog.aspx?RootId=5:798">Consuming ASP.NET 2.0 Web Services in Delphi for Win32 </a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/gubus2.wordpress.com/177/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/gubus2.wordpress.com/177/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gubus2.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gubus2.wordpress.com/177/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gubus2.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gubus2.wordpress.com/177/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gubus2.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gubus2.wordpress.com/177/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gubus2.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gubus2.wordpress.com/177/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gubus2.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gubus2.wordpress.com/177/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gubus2.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gubus2.wordpress.com/177/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gubus2.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gubus2.wordpress.com/177/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=177&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gubus2.wordpress.com/2007/05/04/delphi-kliens-aspnet-20-webszolgaltatas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/395eea308be2d771d18b9305b854e95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gubus</media:title>
		</media:content>
	</item>
		<item>
		<title>QuickCounters.net</title>
		<link>http://gubus2.wordpress.com/2007/04/23/quickcountersnet/</link>
		<comments>http://gubus2.wordpress.com/2007/04/23/quickcountersnet/#comments</comments>
		<pubDate>Mon, 23 Apr 2007 19:05:09 +0000</pubDate>
		<dc:creator>gubus</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://gubus2.wordpress.com/2007/04/23/quickcountersnet/</guid>
		<description><![CDATA[Scott Colestock Biztalk szakértő úr építőkockája a QuickCounters.net library, amivel igen gyorsan lehet teljesítmény számlálókat tenni a gatyaszámláló üzleti enterspájz alkalmazásba. Először is kell gyártani  egy XML-t, ami leírja, hogy milyen komponensünk van,  és annak milyen metódusait mérnénk. Az XML alapján fogja a QuickCounters a számlálókat létrehozni  a Windows-ban.  Aztán a mérni kívánt üzleti kérés [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=174&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Scott Colestock Biztalk szakértő úr építőkockája a QuickCounters.net library, amivel igen gyorsan lehet teljesítmény számlálókat tenni a gatyaszámláló üzleti enterspájz alkalmazásba.</p>
<p>Először is kell gyártani  egy XML-t, ami leírja, hogy milyen komponensünk van,  és annak milyen metódusait mérnénk. Az XML alapján fogja a QuickCounters a számlálókat létrehozni  a Windows-ban.  Aztán a mérni kívánt üzleti kérés elején a metódus azonosítójával értesíteni kell QuickCounters-t az indulásról, majd a try blokk végén SetComplete(), vagy a catch() ágban SetAbort() hívással kell jelezni a mérés végét. Kimenetként minden metódusra lesz egy-egy Performance Object, és mindegyik a következő számlálókkal fog rendelkezni:</p>
<ul>
<li>Request Execution Time (msec)</li>
<li>Requests Completed</li>
<li>Requests Executing</li>
<li>Requests Failed</li>
<li>Requests Started</li>
<li>Requests/Hour</li>
<li>Requests/Min</li>
<li>Requests/Sec</li>
</ul>
<p>Illetve maga a komponens is egy külön Performance Object lesz, őt a Process uptime (sec) fogja jellemezni.</p>
<p>A leíró XML-ben célszerű rövid neveket adni a metódusnak és a komponensnek, mert a Perfromance MMC Snap-In-ben egy Combobox-ban kell kiválasztani a Performance Object-et, és ott a hosszú nevek kilógnak, nem fognak látszani.</p>
<p>Telepítéshez vinni kell a QuickCounters.dll-t az alkalmazással együtt, a leíró XML-t, és a telepítendő gépen installutil, vagy custom action segítségével lehet a QuickCounters.dll-ben található Installer osztályt a leíró XML-lel beindítani. Ezt célszerűen a fejlesztői gépen is meg kell tenni, mert csak akkor fognak látszani a számlálók.</p>
<p>A cucc megy Biztalk alól is, és van WCF pluginja is.</p>
<p><a href="http://www.traceofthought.net/PermaLink,guid,26200471-1a98-4687-9020-6f0091f07b22.aspx">Trace of Thought (Scott Colestock): Introducing QuickCounters&#8230;</a><br />
<a href="http://www.traceofthought.net/PermaLink,guid,f0f391ca-ddad-4ef1-8bed-a6e3ee59e48e.aspx">Trace of Thought (Scott Colestock): QuickCounters update&#8230; </a><br />
<a href="http://www.codeplex.com/quickcounters">CodePlex: QuickCounters.net Project Home Page</a><br />
<a href="http://www.winterdom.com/weblog/CategoryView,category,QuickCounters.aspx">Commonality: QuickCounters + WCF </a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/gubus2.wordpress.com/174/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/gubus2.wordpress.com/174/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gubus2.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gubus2.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gubus2.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gubus2.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gubus2.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gubus2.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gubus2.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gubus2.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gubus2.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gubus2.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gubus2.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gubus2.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gubus2.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gubus2.wordpress.com/174/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gubus2.wordpress.com&amp;blog=245753&amp;post=174&amp;subd=gubus2&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gubus2.wordpress.com/2007/04/23/quickcountersnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/395eea308be2d771d18b9305b854e95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gubus</media:title>
		</media:content>
	</item>
	</channel>
</rss>
