<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>Juanjo's Blog</title><link>http://blogs.clearscreen.com/juanjo/</link><description>Dot Net Development | Technology | Xbox freak :-)</description><managingEditor>Juanjo</managingEditor><dc:language>en-US</dc:language><generator>.Text Version 0.95.2004.102</generator><item><dc:creator>Juanjo</dc:creator><title>How to share Session variables between a legacy ASP and an ASP.Net application</title><link>http://blogs.clearscreen.com/juanjo/archive/2006/02/02/2737.aspx</link><pubDate>Thu, 02 Feb 2006 01:21:00 GMT</pubDate><guid>http://blogs.clearscreen.com/juanjo/archive/2006/02/02/2737.aspx</guid><description>&lt;p&gt;In the project I'm working on, there is a ASP application that mantains the user id information in a Session variable. I had to add a new permisssions management zone to the application in ASP.Net 2.0, and I didn't want to rework again all the Login scenario (the best way to do this should be using the built-in controls in ASP.Net 2.0)... But i decided to get the ASP user id session variable to my ASP.Net application to get the user that logged in in the ASP app.&lt;/p&gt;
&lt;p&gt;Do achieve this, I do need a simple GetSession.ASP page that helps me getting the session variable:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;&amp;lt;%
        &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Option&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Explicit&lt;/span&gt;

        &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Dim&lt;/span&gt; sessionValue
        &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'This is an important check, disallow any remote user to get session variables, and only allows queries from the local server&lt;/span&gt;
        &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; Request.ServerVariables(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"REMOTE_ADDR"&lt;/span&gt;) &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; Request.ServerVariables(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"LOCAL_ADDR"&lt;/span&gt;) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Then&lt;/span&gt; 
            sessionValue &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; Request(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"SessionVar"&lt;/span&gt;)
            &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;trim&lt;/span&gt;(sessionValue) &amp;lt;&amp;gt; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;""&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Then&lt;/span&gt;
              Response.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Write&lt;/span&gt; Session(sessionValue)
            &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt;
        &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Else&lt;/span&gt; 
            Response.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Write&lt;/span&gt; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"Forbidden"&lt;/span&gt;
            Response.Status &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"403"&lt;/span&gt;
        &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt;
&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;%&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Now we can call this page (with a GET GetSession.asp?SessionVar=variable_name) from any ASP.Net code, to get the session variable. But there is a point to check... The ASPSESSION cookie you have to pass to this page, so the server can find the related session variable requested. This is a simple code you can use in your app to get the session variable you need:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;        &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;string&lt;/span&gt; GetSessionVar(HttpContext oContext, &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;string&lt;/span&gt; ASPSessionVar)
        {
            &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;//Define asp page to call:&lt;/span&gt;
            &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;string&lt;/span&gt; ASPSessionVarASP &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;""&lt;/span&gt;;
            System.Uri oURL &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; oContext.Request.Url;
            ASPSessionVarASP &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; oURL.Scheme &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;+&lt;/span&gt; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"://"&lt;/span&gt;
              &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;+&lt;/span&gt; oURL.Host &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;+&lt;/span&gt; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;":"&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;+&lt;/span&gt; oURL.Port.ToString() &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;+&lt;/span&gt; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"/"&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;+&lt;/span&gt; oURL.AbsolutePath.Substring(0, oURL.AbsolutePath.LastIndexOf(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"/"&lt;/span&gt;)) &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;+&lt;/span&gt; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"/"&lt;/span&gt;
              &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;+&lt;/span&gt; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"GetSession.ASP"&lt;/span&gt;;

            &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;// First get the Session Cookies to add to the request. This is important because if no ASPSESSION cookie is present, the &lt;/span&gt;
            &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;// server cannot retrieve the session variable value&lt;/span&gt;
            &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;string&lt;/span&gt;[] ASPCookieName;
            &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;string&lt;/span&gt;[] ASPCookieValue;
            &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;if&lt;/span&gt; (!GetSessionCookie(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;out&lt;/span&gt; ASPCookieName, &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;out&lt;/span&gt; ASPCookieValue))
            {
                &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;return&lt;/span&gt; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;""&lt;/span&gt;;
            }

            &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;// Initialize the WebRequest, with a QueryString parameter with the name&lt;/span&gt;
            HttpWebRequest myRequest &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; (HttpWebRequest)WebRequest.Create(ASPSessionVarASP &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;+&lt;/span&gt; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"?SessionVar="&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;+&lt;/span&gt; ASPSessionVar);

            &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;// Add all ASPSESSION cookies to the request&lt;/span&gt;
            &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;for&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;int&lt;/span&gt; i=0; i&amp;lt;ASPCookieName.Length; i++)
                myRequest.Headers.Add(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"Cookie: "&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;+&lt;/span&gt; ASPCookieName[i] &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;+&lt;/span&gt; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"="&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;+&lt;/span&gt; ASPCookieValue[i]);

            &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;// Send the request and get a response&lt;/span&gt;
            HttpWebResponse myResponse &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; (HttpWebResponse)myRequest.GetResponse();
            Stream receiveStream &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; myResponse.GetResponseStream();
            System.Text.Encoding encode &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; System.Text.Encoding.GetEncoding(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"utf-8"&lt;/span&gt;);
            StreamReader readStream &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;new&lt;/span&gt; StreamReader(receiveStream, encode);

            &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;// Get the response&lt;/span&gt;
            &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;string&lt;/span&gt; sResponse &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; readStream.ReadToEnd();

            &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;// Cleanup&lt;/span&gt;
            myResponse.Close();
            readStream.Close();

            &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;return&lt;/span&gt; sResponse;
        }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Now we need the function that gets the ASPSESSION cookies names and values:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;        &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;private&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;bool&lt;/span&gt; GetSessionCookie(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;out&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;string&lt;/span&gt;[] ASPCookieName, &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;out&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;string&lt;/span&gt;[] ASPCookieValue)
        {
            &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;int&lt;/span&gt; loop1;
            HttpCookie myCookie;     &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;// Cookie variable&lt;/span&gt;

            ArrayList names &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;new&lt;/span&gt; ArrayList();
            ArrayList values &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;new&lt;/span&gt; ArrayList();

            &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;// Capture all cookie names into a string array.&lt;/span&gt;
            String[] CookieArray &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; oContext.Request.Cookies.AllKeys;

            &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;// Grab individual cookie objects by cookie name.&lt;/span&gt;
            &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;for&lt;/span&gt; (loop1 &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; 0; loop1 &amp;lt; CookieArray.Length; loop1++)
            {
                myCookie &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; oContext.Request.Cookies[CookieArray[loop1]];
                &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;if&lt;/span&gt; (myCookie.Name.StartsWith(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"ASPSESSION"&lt;/span&gt;))
                {
                    names.Add(myCookie.Name);
                    values.Add(myCookie.Value);
                }
            }

            &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;// Return the values&lt;/span&gt;
            ASPCookieName &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; (&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;string&lt;/span&gt;[])names.ToArray(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;typeof&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;string&lt;/span&gt;));
            ASPCookieValue &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; (&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;string&lt;/span&gt;[])values.ToArray(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;typeof&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;string&lt;/span&gt;));

            &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;// return true if any cookie found&lt;/span&gt;
            &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;return&lt;/span&gt; (names.Count &amp;gt; 0);
        }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;Now, in the ASP.Net page you need the legacy session variable, you have to call something like this:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;
                &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;string&lt;/span&gt; userid &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; aspSession.GetSessionVar(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;this&lt;/span&gt;.Context, &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"userId"&lt;/span&gt;);
&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Hope this works for you as it did for me :-)&lt;br /&gt;&lt;/p&gt;&lt;img src ="http://blogs.clearscreen.com/juanjo/aggbug/2737.aspx" width = "1" height = "1" /&gt;</description><body xmlns="http://www.w3.org/1999/xhtml"><p>In the project I'm working on, there is a ASP application that mantains the user id information in a Session variable. I had to add a new permisssions management zone to the application in ASP.Net 2.0, and I didn't want to rework again all the Login scenario (the best way to do this should be using the built-in controls in ASP.Net 2.0)... But i decided to get the ASP user id session variable to my ASP.Net application to get the user that logged in in the ASP app.</p>
<p>Do achieve this, I do need a simple GetSession.ASP page that helps me getting the session variable:</p>
<p></p><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px">&lt;%
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Option</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Explicit</span>

        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Dim</span> sessionValue
        <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'This is an important check, disallow any remote user to get session variables, and only allows queries from the local server</span>
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span> Request.ServerVariables(<span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"REMOTE_ADDR"</span>) <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> Request.ServerVariables(<span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"LOCAL_ADDR"</span>) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Then</span> 
            sessionValue <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> Request(<span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"SessionVar"</span>)
            <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">trim</span>(sessionValue) &lt;&gt; <span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">""</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Then</span>
              Response.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Write</span> Session(sessionValue)
            <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span>
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Else</span> 
            Response.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Write</span> <span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"Forbidden"</span>
            Response.Status <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> <span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"403"</span>
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span>
<span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">%</span>&gt;</span></pre>
<p>Now we can call this page (with a GET GetSession.asp?SessionVar=variable_name) from any ASP.Net code, to get the session variable. But there is a point to check... The ASPSESSION cookie you have to pass to this page, so the server can find the related session variable requested. This is a simple code you can use in your app to get the session variable you need:</p>
<p></p><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px">        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">public</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">string</span> GetSessionVar(HttpContext oContext, <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">string</span> ASPSessionVar)
        {
            <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">//Define asp page to call:</span>
            <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">string</span> ASPSessionVarASP <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> <span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">""</span>;
            System.Uri oURL <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> oContext.Request.Url;
            ASPSessionVarASP <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> oURL.Scheme <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">+</span> <span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"://"</span>
              <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">+</span> oURL.Host <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">+</span> <span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">":"</span> <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">+</span> oURL.Port.ToString() <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">+</span> <span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"/"</span> <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">+</span> oURL.AbsolutePath.Substring(0, oURL.AbsolutePath.LastIndexOf(<span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"/"</span>)) <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">+</span> <span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"/"</span>
              <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">+</span> <span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"GetSession.ASP"</span>;

            <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">// First get the Session Cookies to add to the request. This is important because if no ASPSESSION cookie is present, the </span>
            <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">// server cannot retrieve the session variable value</span>
            <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">string</span>[] ASPCookieName;
            <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">string</span>[] ASPCookieValue;
            <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">if</span> (!GetSessionCookie(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">out</span> ASPCookieName, <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">out</span> ASPCookieValue))
            {
                <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">return</span> <span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">""</span>;
            }

            <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">// Initialize the WebRequest, with a QueryString parameter with the name</span>
            HttpWebRequest myRequest <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> (HttpWebRequest)WebRequest.Create(ASPSessionVarASP <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">+</span> <span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"?SessionVar="</span> <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">+</span> ASPSessionVar);

            <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">// Add all ASPSESSION cookies to the request</span>
            <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">for</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">int</span> i=0; i&lt;ASPCookieName.Length; i++)
                myRequest.Headers.Add(<span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"Cookie: "</span> <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">+</span> ASPCookieName[i] <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">+</span> <span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"="</span> <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">+</span> ASPCookieValue[i]);

            <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">// Send the request and get a response</span>
            HttpWebResponse myResponse <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> (HttpWebResponse)myRequest.GetResponse();
            Stream receiveStream <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> myResponse.GetResponseStream();
            System.Text.Encoding encode <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> System.Text.Encoding.GetEncoding(<span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"utf-8"</span>);
            StreamReader readStream <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">new</span> StreamReader(receiveStream, encode);

            <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">// Get the response</span>
            <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">string</span> sResponse <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> readStream.ReadToEnd();

            <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">// Cleanup</span>
            myResponse.Close();
            readStream.Close();

            <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">return</span> sResponse;
        }</span></pre>
<p>Now we need the function that gets the ASPSESSION cookies names and values:</p>
<p></p><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px">        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">private</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">bool</span> GetSessionCookie(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">out</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">string</span>[] ASPCookieName, <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">out</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">string</span>[] ASPCookieValue)
        {
            <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">int</span> loop1;
            HttpCookie myCookie;     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">// Cookie variable</span>

            ArrayList names <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">new</span> ArrayList();
            ArrayList values <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">new</span> ArrayList();

            <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">// Capture all cookie names into a string array.</span>
            String[] CookieArray <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> oContext.Request.Cookies.AllKeys;

            <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">// Grab individual cookie objects by cookie name.</span>
            <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">for</span> (loop1 <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> 0; loop1 &lt; CookieArray.Length; loop1++)
            {
                myCookie <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> oContext.Request.Cookies[CookieArray[loop1]];
                <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">if</span> (myCookie.Name.StartsWith(<span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"ASPSESSION"</span>))
                {
                    names.Add(myCookie.Name);
                    values.Add(myCookie.Value);
                }
            }

            <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">// Return the values</span>
            ASPCookieName <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> (<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">string</span>[])names.ToArray(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">typeof</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">string</span>));
            ASPCookieValue <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> (<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">string</span>[])values.ToArray(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">typeof</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">string</span>));

            <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">// return true if any cookie found</span>
            <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">return</span> (names.Count &gt; 0);
        }</span></pre>
<p><br />Now, in the ASP.Net page you need the legacy session variable, you have to call something like this:</p>
<p></p><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px">
                <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">string</span> userid <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> aspSession.GetSessionVar(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">this</span>.Context, <span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"userId"</span>);
</span></pre>
<p>Hope this works for you as it did for me :-)<br /></p><img src ="http://blogs.clearscreen.com/juanjo/aggbug/2737.aspx" width = "1" height = "1" /></body></item><item><dc:creator>Juanjo</dc:creator><title>Back in town</title><link>http://blogs.clearscreen.com/juanjo/archive/2005/09/12/2412.aspx</link><pubDate>Mon, 12 Sep 2005 19:56:00 GMT</pubDate><guid>http://blogs.clearscreen.com/juanjo/archive/2005/09/12/2412.aspx</guid><description>&lt;p&gt;Hi guys!&lt;/p&gt;
&lt;p&gt;After a few weeks of holidays, a week in Tenerife, some days in Menorca, and a week also in Portugal (Lisboa and Algarve), now I've charged my batteries and I'm back to kick some butts... Ok, maybe I'm not going to kick anybody, but I'm going to write some posts here and there...&lt;/p&gt;
&lt;p&gt;I left the project where i was for the last year, and for now I will stay in ilitia's offices doing some internal projects with Visual Studio 2005 and SQL Server 2005... To start, I need to check what's new in these new versions, so I'm going to read the free online courses that Microsoft provides...&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.microsoftelearning.com/visualstudio2005/"&gt;https://www.microsoftelearning.com/visualstudio2005/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;See you very soon.&lt;/p&gt;&lt;img src ="http://blogs.clearscreen.com/juanjo/aggbug/2412.aspx" width = "1" height = "1" /&gt;</description><body xmlns="http://www.w3.org/1999/xhtml"><p>Hi guys!</p>
<p>After a few weeks of holidays, a week in Tenerife, some days in Menorca, and a week also in Portugal (Lisboa and Algarve), now I've charged my batteries and I'm back to kick some butts... Ok, maybe I'm not going to kick anybody, but I'm going to write some posts here and there...</p>
<p>I left the project where i was for the last year, and for now I will stay in ilitia's offices doing some internal projects with Visual Studio 2005 and SQL Server 2005... To start, I need to check what's new in these new versions, so I'm going to read the free online courses that Microsoft provides...</p>
<p><a href="https://www.microsoftelearning.com/visualstudio2005/">https://www.microsoftelearning.com/visualstudio2005/</a></p>
<p>See you very soon.</p><img src ="http://blogs.clearscreen.com/juanjo/aggbug/2412.aspx" width = "1" height = "1" /></body></item><item><dc:creator>Juanjo</dc:creator><title>Biztalk 2004 Custom Pipelines</title><link>http://blogs.clearscreen.com/juanjo/archive/2005/05/28/1710.aspx</link><pubDate>Sat, 28 May 2005 17:12:00 GMT</pubDate><guid>http://blogs.clearscreen.com/juanjo/archive/2005/05/28/1710.aspx</guid><description>&lt;p&gt;In the project currently I am working, I am migrating a legacy BizTalk 2002 application to BizTalk 2004. As you probably already know, the migration path between the two products is far from easy... So I am rewriting all from scratch so I can take all advantadges that .Net provides, and avoiding the legacy limitations from COM world...&lt;/p&gt;
&lt;p&gt;In the current post, I will talk about Custom Pipeline Components. If you know already BTS 2002, the Pipeline Components in BTS 2004 are similar from the Application Integration Components (AIC) from BTS 2000 / 2002. And I am working in a Custom Pipeline Component for transforming an XML with a propietary (and very huge) XSL to convert this XML to a MIME document. Also, this Pipeline Component is reading the MIME response from the remote service and extracting the embedded XML document.&lt;/p&gt;
&lt;p&gt;The Custom Pipeline inherits from some interfaces, and one of this, IComponent, exposes a public method named Execute. This method is executed every time the Custom Pipeline Component is called from a Pipeline.&lt;/p&gt;
&lt;p&gt;And in this step was where my troubles arised... I had this code, in the Execute method, that was transforming the MIME into an XML string:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;

  &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)
  {
   IBaseMessagePart bodyPart &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; inmsg.BodyPart;
   Stream originalStrm &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;;
   MemoryStream strm &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; MemoryStream();

   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;try&lt;/span&gt;
   {   
    &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; (bodyPart!=&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;)
    {
     &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;// Get a *copy* of the original input stream&lt;/span&gt;
     originalStrm &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; bodyPart.Data;
     &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; (originalStrm !&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;)
     {
      &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//Read Incoming data&lt;/span&gt;
      &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; data &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;""&lt;/span&gt;;

      StreamReader sreader &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; StreamReader(originalStrm, System.Text.Encoding.UTF8);

      &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//Receive pipeline, parse MIME document and extract XML&lt;/span&gt;
      data &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt;.fromMIME( sreader.ReadToEnd() );     

      &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//Send the data back to the Message&lt;/span&gt;
      StreamWriter swriter &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; StreamWriter(strm, System.Text.Encoding.UTF8);
      swriter.Write(data);
      swriter.Flush();
      strm.Seek(0, System.IO.SeekOrigin.Begin);

     }
    }
   }
   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;catch&lt;/span&gt; (Exception ex)
   {
    System.Diagnostics.EventLog.WriteEntry(ex.Source, ex.Message &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"\n"&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
    strm &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; (MemoryStream) originalStrm;
   }
   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;finally&lt;/span&gt;
   {
    bodyPart.Data &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; strm;
    pc.ResourceTracker.AddResource( strm );
   }
            
   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; inmsg;
  }
&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;This code was working perfect for me... Until I connect it to my Receive Pipeline and to my Orchestration. When unit testing the orchestration, all messages were suspended, with an exception saying that the message, with an empty namespace, was not corresponding with the expected one, "www.clearscreen.com#Response". It was very disssapointing, because the XML was in a proper format and with it expected namespace in place, the root tag was "Response" and its namespace was "www.clearscreen.com" : &lt;/p&gt;
&lt;p&gt;&lt;response xmlns="www.clearscreen.com"&gt;&lt;/response&gt;&lt;/p&gt;
&lt;p&gt;But this was not enough for BizTalk to route the message. I discovered that we need to promote a property of the message in the Custom Pipeline: &lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;

  &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)
  {
   IBaseMessagePart bodyPart &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; inmsg.BodyPart;
   Stream originalStrm &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;;
   MemoryStream strm &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; MemoryStream();

   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;try&lt;/span&gt;
   {   
    &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; (bodyPart!=&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;)
    {
     &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;// Get a *copy* of the original input stream&lt;/span&gt;
     originalStrm &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; bodyPart.Data;
     &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; (originalStrm !&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;)
     {
      &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//Read Incoming data&lt;/span&gt;
      &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; data &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;""&lt;/span&gt;;

      StreamReader sreader &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; StreamReader(originalStrm, System.Text.Encoding.UTF8);

      &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//Receive pipeline, parse MIME document and extract XML&lt;/span&gt;
      data &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt;.fromMIME( sreader.ReadToEnd() );     


      &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//Send the data back to the Message&lt;/span&gt;
      StreamWriter swriter &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; StreamWriter(strm, System.Text.Encoding.UTF8);
      swriter.Write(data);
      swriter.Flush();
      strm.Seek(0, System.IO.SeekOrigin.Begin);

      &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;// IMPORTANT CODE HERE: Promote the message type context property&lt;/span&gt;
      &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; systemPropertiesNamespace &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"http://schemas.microsoft.com/BizTalk/2003/system-properties"&lt;/span&gt;;
      &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; messageType &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"www.clearscreen.com#Response"&lt;/span&gt;; 
      inmsg.Context.Promote(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"MessageType"&lt;/span&gt;, systemPropertiesNamespace, messageType);

     }
    }
   }
   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;catch&lt;/span&gt; (Exception ex)
   {
    System.Diagnostics.EventLog.WriteEntry(ex.Source, ex.Message &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"\n"&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
    strm &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; (MemoryStream) originalStrm;
   }
   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;finally&lt;/span&gt;
   {
    bodyPart.Data &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; strm;
    pc.ResourceTracker.AddResource( strm );
   }
            
   &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; inmsg;
  }

&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Hope this helps!&lt;/p&gt;&lt;img src ="http://blogs.clearscreen.com/juanjo/aggbug/1710.aspx" width = "1" height = "1" /&gt;</description><body xmlns="http://www.w3.org/1999/xhtml"><p>In the project currently I am working, I am migrating a legacy BizTalk 2002 application to BizTalk 2004. As you probably already know, the migration path between the two products is far from easy... So I am rewriting all from scratch so I can take all advantadges that .Net provides, and avoiding the legacy limitations from COM world...</p>
<p>In the current post, I will talk about Custom Pipeline Components. If you know already BTS 2002, the Pipeline Components in BTS 2004 are similar from the Application Integration Components (AIC) from BTS 2000 / 2002. And I am working in a Custom Pipeline Component for transforming an XML with a propietary (and very huge) XSL to convert this XML to a MIME document. Also, this Pipeline Component is reading the MIME response from the remote service and extracting the embedded XML document.</p>
<p>The Custom Pipeline inherits from some interfaces, and one of this, IComponent, exposes a public method named Execute. This method is executed every time the Custom Pipeline Component is called from a Pipeline.</p>
<p>And in this step was where my troubles arised... I had this code, in the Execute method, that was transforming the MIME into an XML string:</p>
<p></p><pre><span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">

  <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span> IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)
  {
   IBaseMessagePart bodyPart <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> inmsg.BodyPart;
   Stream originalStrm <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>;
   MemoryStream strm <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> MemoryStream();

   <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">try</span>
   {   
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (bodyPart!=<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)
    {
     <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">// Get a *copy* of the original input stream</span>
     originalStrm <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> bodyPart.Data;
     <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (originalStrm !<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)
     {
      <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//Read Incoming data</span>
      <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> data <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">""</span>;

      StreamReader sreader <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> StreamReader(originalStrm, System.Text.Encoding.UTF8);

      <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//Receive pipeline, parse MIME document and extract XML</span>
      data <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">this</span>.fromMIME( sreader.ReadToEnd() );     

      <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//Send the data back to the Message</span>
      StreamWriter swriter <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> StreamWriter(strm, System.Text.Encoding.UTF8);
      swriter.Write(data);
      swriter.Flush();
      strm.Seek(0, System.IO.SeekOrigin.Begin);

     }
    }
   }
   <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">catch</span> (Exception ex)
   {
    System.Diagnostics.EventLog.WriteEntry(ex.Source, ex.Message <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"\n"</span> <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
    strm <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> (MemoryStream) originalStrm;
   }
   <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">finally</span>
   {
    bodyPart.Data <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> strm;
    pc.ResourceTracker.AddResource( strm );
   }
            
   <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> inmsg;
  }
</span></pre>
<p>This code was working perfect for me... Until I connect it to my Receive Pipeline and to my Orchestration. When unit testing the orchestration, all messages were suspended, with an exception saying that the message, with an empty namespace, was not corresponding with the expected one, "www.clearscreen.com#Response". It was very disssapointing, because the XML was in a proper format and with it expected namespace in place, the root tag was "Response" and its namespace was "www.clearscreen.com" : </p>
<p><response xmlns="www.clearscreen.com"></response></p>
<p>But this was not enough for BizTalk to route the message. I discovered that we need to promote a property of the message in the Custom Pipeline: </p>
<p></p><pre><span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">

  <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span> IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)
  {
   IBaseMessagePart bodyPart <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> inmsg.BodyPart;
   Stream originalStrm <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>;
   MemoryStream strm <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> MemoryStream();

   <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">try</span>
   {   
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (bodyPart!=<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)
    {
     <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">// Get a *copy* of the original input stream</span>
     originalStrm <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> bodyPart.Data;
     <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (originalStrm !<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)
     {
      <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//Read Incoming data</span>
      <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> data <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">""</span>;

      StreamReader sreader <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> StreamReader(originalStrm, System.Text.Encoding.UTF8);

      <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//Receive pipeline, parse MIME document and extract XML</span>
      data <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">this</span>.fromMIME( sreader.ReadToEnd() );     


      <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//Send the data back to the Message</span>
      StreamWriter swriter <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> StreamWriter(strm, System.Text.Encoding.UTF8);
      swriter.Write(data);
      swriter.Flush();
      strm.Seek(0, System.IO.SeekOrigin.Begin);

      <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">// IMPORTANT CODE HERE: Promote the message type context property</span>
      <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> systemPropertiesNamespace <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"http://schemas.microsoft.com/BizTalk/2003/system-properties"</span>;
      <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> messageType <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"www.clearscreen.com#Response"</span>; 
      inmsg.Context.Promote(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"MessageType"</span>, systemPropertiesNamespace, messageType);

     }
    }
   }
   <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">catch</span> (Exception ex)
   {
    System.Diagnostics.EventLog.WriteEntry(ex.Source, ex.Message <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"\n"</span> <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
    strm <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> (MemoryStream) originalStrm;
   }
   <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">finally</span>
   {
    bodyPart.Data <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> strm;
    pc.ResourceTracker.AddResource( strm );
   }
            
   <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> inmsg;
  }

</span></pre>
<p>Hope this helps!</p><img src ="http://blogs.clearscreen.com/juanjo/aggbug/1710.aspx" width = "1" height = "1" /></body></item><item><dc:creator>Juanjo</dc:creator><title>Serializing issues</title><link>http://blogs.clearscreen.com/juanjo/archive/2005/04/26/1421.aspx</link><pubDate>Tue, 26 Apr 2005 16:56:00 GMT</pubDate><guid>http://blogs.clearscreen.com/juanjo/archive/2005/04/26/1421.aspx</guid><description>&lt;p&gt;&lt;font face="Verdana" size="2"&gt;Wow... Two posts in a day! Just incredible for me!!! (LOL, this is for Miguel that is always bugging me to post) :o)&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Verdana" size="2"&gt;As I told in the previous post, I am having difficulties when serializing to Xml with DateTime and Boolean types, because they are serialized in a format I don´t need. For example, DateTime types serialize like 2005-01-23T00:01:02.000000+02:00 (with millisecs an time zone info). I do not need this. I have workarounded this in the following way:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Verdana" size="2"&gt;When you run XSD.exe with a schema, it gives you a class (or a collection of them). In each class you can find this method (for a DateTime class):&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt; 
  &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;///Original method&lt;/span&gt;
  [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
  &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;public&lt;/span&gt; System.DateTime DateDistributed 
  {
   get 
   {
    &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;return&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;this&lt;/span&gt;.dateDistributedField;
   }
   set 
   {
    &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;this&lt;/span&gt;.dateDistributedField &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; value;
   }
  }
&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;font face="Verdana" size="2"&gt;If you change the property to this, you can control the format the DateTime is serialized with.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt; 
  &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;/// &lt;/span&gt;
  &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;/// This is the new method, I've decorated it with XmlElementAttribute attribute and the name of the original Property.&lt;/span&gt;
  &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;/// The DateTime is serialized as a String, and you can control the output format for the date / time.&lt;/span&gt;
  &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;/// &lt;/span&gt;
  [System.Xml.Serialization.XmlElementAttribute(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"DateDistributed"&lt;/span&gt;, Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
  [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
  &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;string&lt;/span&gt; __DateTime_DateDistributed
  {
   get
   {
    &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;if&lt;/span&gt; (&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;this&lt;/span&gt;.dateDistributedField !&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; System.DateTime.MinValue)
     &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;return&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;this&lt;/span&gt;.dateDistributedField.ToString(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"yyyy-MM-ddTHH:mm:ss"&lt;/span&gt;);
    &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;else&lt;/span&gt; 
     &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;return&lt;/span&gt; System.String.Empty;
   }
   set
   {
    &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;this&lt;/span&gt;.dateDistributedField &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; System.DateTime.Parse(value);
   }
  }

  &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;/// &lt;/span&gt;
  &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;/// This is the old method, I've decorated it with XmlIgnore attribute. This makes the original property not serializing.&lt;/span&gt;
  &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;/// &lt;/span&gt;
  [System.Xml.Serialization.XmlIgnore()]
  &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;public&lt;/span&gt; System.DateTime DateDistributed 
  {
   get 
   {
    &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;return&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;this&lt;/span&gt;.dateDistributedField;
   }
   set 
   {
    &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;this&lt;/span&gt;.dateDistributedField &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; value;
   }
  }
&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;p&gt;&lt;font face="Verdana" size="2"&gt;Yes, I know this is not the best solution if you have a large schema (like mine), but at least I can control how I output my values to Xml.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Verdana" size="2"&gt;The best solution would be change the XmlSerializer do the serialization of the types, but I didn't find out how to do it... If you know please let me know!&lt;/font&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;&lt;img src ="http://blogs.clearscreen.com/juanjo/aggbug/1421.aspx" width = "1" height = "1" /&gt;</description><body xmlns="http://www.w3.org/1999/xhtml"><p><font face="Verdana" size="2">Wow... Two posts in a day! Just incredible for me!!! (LOL, this is for Miguel that is always bugging me to post) :o)</font></p>
<p><font face="Verdana" size="2">As I told in the previous post, I am having difficulties when serializing to Xml with DateTime and Boolean types, because they are serialized in a format I don´t need. For example, DateTime types serialize like 2005-01-23T00:01:02.000000+02:00 (with millisecs an time zone info). I do not need this. I have workarounded this in the following way:</font></p>
<p><font face="Verdana" size="2">When you run XSD.exe with a schema, it gives you a class (or a collection of them). In each class you can find this method (for a DateTime class):</font></p>
<p></p><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px"> 
  <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">///Original method</span>
  [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
  <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">public</span> System.DateTime DateDistributed 
  {
   get 
   {
    <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">return</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">this</span>.dateDistributedField;
   }
   set 
   {
    <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">this</span>.dateDistributedField <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> value;
   }
  }
</span></pre>
<p><font face="Verdana" size="2">If you change the property to this, you can control the format the DateTime is serialized with.</font></p>
<p></p><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px"> 
  <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">/// </span>
  <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">/// This is the new method, I've decorated it with XmlElementAttribute attribute and the name of the original Property.</span>
  <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">/// The DateTime is serialized as a String, and you can control the output format for the date / time.</span>
  <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">/// </span>
  [System.Xml.Serialization.XmlElementAttribute(<span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"DateDistributed"</span>, Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
  [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
  <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">public</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">string</span> __DateTime_DateDistributed
  {
   get
   {
    <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">if</span> (<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">this</span>.dateDistributedField !<span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> System.DateTime.MinValue)
     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">return</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">this</span>.dateDistributedField.ToString(<span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"yyyy-MM-ddTHH:mm:ss"</span>);
    <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">else</span> 
     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">return</span> System.String.Empty;
   }
   set
   {
    <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">this</span>.dateDistributedField <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> System.DateTime.Parse(value);
   }
  }

  <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">/// </span>
  <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">/// This is the old method, I've decorated it with XmlIgnore attribute. This makes the original property not serializing.</span>
  <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">/// </span>
  [System.Xml.Serialization.XmlIgnore()]
  <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">public</span> System.DateTime DateDistributed 
  {
   get 
   {
    <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">return</span> <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">this</span>.dateDistributedField;
   }
   set 
   {
    <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">this</span>.dateDistributedField <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> value;
   }
  }
</span></pre><br />
<p><font face="Verdana" size="2">Yes, I know this is not the best solution if you have a large schema (like mine), but at least I can control how I output my values to Xml.</font></p>
<p><font face="Verdana" size="2">The best solution would be change the XmlSerializer do the serialization of the types, but I didn't find out how to do it... If you know please let me know!</font></p>
<p> </p><img src ="http://blogs.clearscreen.com/juanjo/aggbug/1421.aspx" width = "1" height = "1" /></body></item><item><dc:creator>Juanjo</dc:creator><title>Playing with XSD.EXE</title><link>http://blogs.clearscreen.com/juanjo/archive/2005/04/26/1416.aspx</link><pubDate>Tue, 26 Apr 2005 11:47:00 GMT</pubDate><guid>http://blogs.clearscreen.com/juanjo/archive/2005/04/26/1416.aspx</guid><description>&lt;p&gt;&lt;font face="Verdana" size="2"&gt;In the project I'm currently working on, I needed to create a XML from a pretty complex XSD Schema. This schema is very complex because has a lot of imports and includes. The logical way to create a Xml from the XSD is running the XSD.EXE tool (that tool is included in Visual Studio 2003) to generate a class hierarchy, and then, after including this generated classes in the project, populate this classes and serialize them to Xml with the XmlSerializer object.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Verdana" size="2"&gt;Here comes the problem: XSD.EXE always returned me the error "Specified cast is not valid". After a few research, I had seen that XSD.EXE was not able to support some sympleTypes and also the "xsd:include schemaLocation" in a proper way. I've tryed some other tools with no luck, XSDObjectGen or CodeXS also failed to generate for me an object that I can use to generate my Xml.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Verdana" size="2"&gt;The solution for me was a bit strange, but successful anyway... I tryed to generate the object with an installation of Visual Studio 2005 beta that I have in a virtual machine. I ran the XSD.EXE tool with the schema, and in the first try, the tool generated the C# classes properly. I was surprised, but tryed to import the .cs file into my Visual Studio 2003 project. After removing some duplicated values in an enumerated type, it was compiling successfully... And it works very fine!&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Verdana" size="2"&gt;Now the trouble I have is the DateTime and Boolean types are non serializing like I need, boolean values are serializing with it's literal value 'true' - 'false' instead of '1' - '0', and the DateTime values are serializing in ISO format, but with the time zone, and I don't need this... But this will be for another article!&lt;/font&gt;&lt;/p&gt;&lt;img src ="http://blogs.clearscreen.com/juanjo/aggbug/1416.aspx" width = "1" height = "1" /&gt;</description><body xmlns="http://www.w3.org/1999/xhtml"><p><font face="Verdana" size="2">In the project I'm currently working on, I needed to create a XML from a pretty complex XSD Schema. This schema is very complex because has a lot of imports and includes. The logical way to create a Xml from the XSD is running the XSD.EXE tool (that tool is included in Visual Studio 2003) to generate a class hierarchy, and then, after including this generated classes in the project, populate this classes and serialize them to Xml with the XmlSerializer object.</font></p>
<p><font face="Verdana" size="2">Here comes the problem: XSD.EXE always returned me the error "Specified cast is not valid". After a few research, I had seen that XSD.EXE was not able to support some sympleTypes and also the "xsd:include schemaLocation" in a proper way. I've tryed some other tools with no luck, XSDObjectGen or CodeXS also failed to generate for me an object that I can use to generate my Xml.</font></p>
<p><font face="Verdana" size="2">The solution for me was a bit strange, but successful anyway... I tryed to generate the object with an installation of Visual Studio 2005 beta that I have in a virtual machine. I ran the XSD.EXE tool with the schema, and in the first try, the tool generated the C# classes properly. I was surprised, but tryed to import the .cs file into my Visual Studio 2003 project. After removing some duplicated values in an enumerated type, it was compiling successfully... And it works very fine!</font></p>
<p><font face="Verdana" size="2">Now the trouble I have is the DateTime and Boolean types are non serializing like I need, boolean values are serializing with it's literal value 'true' - 'false' instead of '1' - '0', and the DateTime values are serializing in ISO format, but with the time zone, and I don't need this... But this will be for another article!</font></p><img src ="http://blogs.clearscreen.com/juanjo/aggbug/1416.aspx" width = "1" height = "1" /></body></item></channel></rss>