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

<channel>
	<title>Marco Silva, Author at Blog IT</title>
	<atom:link href="https://blogit.create.pt/author/marcosilva/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Create IT blogger community</description>
	<lastBuildDate>Thu, 10 Jan 2019 14:18:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>DevDays 2009</title>
		<link>https://blogit.create.pt/marcosilva/2009/02/23/devdays-2009-2/</link>
					<comments>https://blogit.create.pt/marcosilva/2009/02/23/devdays-2009-2/#respond</comments>
		
		<dc:creator><![CDATA[Marco Silva]]></dc:creator>
		<pubDate>Mon, 23 Feb 2009 04:50:49 +0000</pubDate>
				<category><![CDATA[WebServices]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[REST]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/marcosilva/?p=31</guid>

					<description><![CDATA[<p>Realizou-se a semana passada o DevDays 2009, o evento anual da Microsoft Portugal destinado a juntar profissionais e curiosos em torno das tecnologias da casa, que este ano foi organizado no campus do Tagus Park do Instituto Superior Técnico. Para mim foi uma novidade a participação neste tipo de eventos, e logo com a oportunidade [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2009/02/23/devdays-2009-2/">DevDays 2009</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Realizou-se a semana passada o <strong><a href="http://www.devdays09.com">DevDays 2009</a></strong>, o evento anual da Microsoft Portugal destinado a juntar profissionais e curiosos em torno das tecnologias da casa, que este ano foi organizado no campus do Tagus Park do <a href="http://www.ist.utl.pt/html/campus/tagus/">Instituto Superior Técnico</a>.</p>
<p>Para mim foi uma novidade a participação neste tipo de eventos, e logo com a oportunidade de fazer uma sessão sobre a <strong>Implementação de Serviços REST sobre WCF</strong>, que segundo me disseram 😉 , correu bastante bem.</p>
<p>Além de mim, outros três colegas da <strong>|create|<font color="#ff0000">it</font>|</strong> fizeram apresentações no DevDays este ano. Estou a falar do <a href="http://blogit.create.pt/blogs/joaomartins"><strong>Jota</strong></a>, que já é veterano nestas andanças, e do <strong><a href="http://blogit.create.pt/blogs/andrevala/default.aspx">André</a> </strong>e o <strong><a href="http://blogit.create.pt/blogs/raulribeiro">Raul</a></strong>.</p>
<p>Globalmente o evento correu bem e foi uma boa oportunidade para conhecer pessoas e trocar experiências interessantes.</p>
<p>Posteriormente vou editar este post com a informação que apresentei na sessão.</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2009/02/23/devdays-2009-2/">DevDays 2009</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/marcosilva/2009/02/23/devdays-2009-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>.NET XML Serialization of CDATA ATTRIBUTE</title>
		<link>https://blogit.create.pt/marcosilva/2008/11/23/net-xml-serialization-of-cdata-attribute/</link>
					<comments>https://blogit.create.pt/marcosilva/2008/11/23/net-xml-serialization-of-cdata-attribute/#comments</comments>
		
		<dc:creator><![CDATA[Marco Silva]]></dc:creator>
		<pubDate>Sun, 23 Nov 2008 14:05:11 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[.NET]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/marcosilva/?p=51</guid>

					<description><![CDATA[<p>Recently I needed to create a .NET class (C#) that when serialized should contain a CDATA attribute similar to this: &#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34; ?&#62; &#60;RootNode Type=&#34;zzzzz&#34; Version=&#34;1&#34; &#62; &#60;CDataAttribute&#62; &#60;![CDATA[ &#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34; ?&#62; ]]&#62; &#60;/CDataAttribute&#62; &#60;/RootNode&#62; &#160; I started by creating a schema for validating this xml that can be (generated with xsd.exe and [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2008/11/23/net-xml-serialization-of-cdata-attribute/">.NET XML Serialization of CDATA ATTRIBUTE</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Recently I needed to create a .NET class (C#) that when serialized should contain a <strong>CDATA</strong> attribute similar to this:</p>
<div>
<div>
<pre><span style="color: #0000ff">&lt;?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">=&quot;1.0&quot;</span> <span style="color: #ff0000">encoding</span><span style="color: #0000ff">=&quot;utf-8&quot;</span> ?<span style="color: #0000ff">&gt;</span></pre>
<pre><span style="color: #0000ff">&lt;</span><span style="color: #800000">RootNode</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">=&quot;zzzzz&quot;</span> <span style="color: #ff0000">Version</span><span style="color: #0000ff">=&quot;1&quot;</span> <span style="color: #0000ff">&gt;</span>    </pre>
<pre>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">CDataAttribute</span><span style="color: #0000ff">&gt;</span></pre>
<pre>        <span style="color: #0000ff">&lt;!</span>[CDATA[</pre>
<pre>         <span style="color: #0000ff">&lt;?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">=&quot;1.0&quot;</span> <span style="color: #ff0000">encoding</span><span style="color: #0000ff">=&quot;utf-8&quot;</span> ?<span style="color: #0000ff">&gt;</span></pre>
<pre>        ]]<span style="color: #0000ff">&gt;</span></pre>
<pre>    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">CDataAttribute</span><span style="color: #0000ff">&gt;</span>    </pre>
<pre><span style="color: #0000ff">&lt;/</span><span style="color: #800000">RootNode</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p><p>&#160;</p>
<p>I started by creating a schema for validating this xml that can be (generated with <strong>xsd.exe </strong>and slightly altered):</p>
<div>
<div>
<pre><span style="color: #0000ff">&lt;?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">=&quot;1.0&quot;</span> <span style="color: #ff0000">encoding</span><span style="color: #0000ff">=&quot;utf-8&quot;</span>?<span style="color: #0000ff">&gt;</span></pre>
<pre><span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:schema</span> <span style="color: #ff0000">id</span><span style="color: #0000ff">=&quot;Example&quot;</span> <span style="color: #ff0000">xmlns:xs</span><span style="color: #0000ff">=&quot;http://www.w3.org/2001/XMLSchema&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre>  <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:element</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;RootNode&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:complexType</span><span style="color: #0000ff">&gt;</span></pre>
<pre>      <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:sequence</span><span style="color: #0000ff">&gt;</span></pre>
<pre>        <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:element</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;CDataAttribute&quot;</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;xs:string&quot;</span> <span style="color: #ff0000">minOccurs</span><span style="color: #0000ff">=&quot;0&quot;</span><span style="color: #0000ff">/&gt;</span></pre>
<pre>      <span style="color: #0000ff">&lt;/</span><span style="color: #800000">xs:sequence</span><span style="color: #0000ff">&gt;</span></pre>
<pre>      <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:attribute</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;Type&quot;</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;xs:string&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<pre>      <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:attribute</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;Version&quot;</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;xs:string&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<pre>    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">xs:complexType</span><span style="color: #0000ff">&gt;</span></pre>
<pre>  <span style="color: #0000ff">&lt;/</span><span style="color: #800000">xs:element</span><span style="color: #0000ff">&gt;</span></pre>
<pre>  <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:element</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;Example&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:complexType</span><span style="color: #0000ff">&gt;</span></pre>
<pre>      <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:choice</span> <span style="color: #ff0000">minOccurs</span><span style="color: #0000ff">=&quot;0&quot;</span> <span style="color: #ff0000">maxOccurs</span><span style="color: #0000ff">=&quot;unbounded&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre>        <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:element</span> <span style="color: #ff0000">ref</span><span style="color: #0000ff">=&quot;RootNode&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<pre>      <span style="color: #0000ff">&lt;/</span><span style="color: #800000">xs:choice</span><span style="color: #0000ff">&gt;</span></pre>
<pre>    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">xs:complexType</span><span style="color: #0000ff">&gt;</span></pre>
<pre>  <span style="color: #0000ff">&lt;/</span><span style="color: #800000">xs:element</span><span style="color: #0000ff">&gt;</span></pre>
<pre><span style="color: #0000ff">&lt;/</span><span style="color: #800000">xs:schema</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p>Note that the <strong>CDataAttribute</strong> is specified as type string and I could not find any type for referring a CDATA.</p>
<p>Now if you take this schema and generate a class from it (again with <strong>xsd.exe</strong>) you will see that the CDataAttribute is, as expected, represented by a string.</p>
<div>
<div>
<pre><span style="color: #0000ff">private</span> <span style="color: #0000ff">string</span> cDataAttributeField;</pre>
</p></div>
</div>
<p><p>If you use the generated class and serialize a object from it, the .NET serializer will not encode the CDataAttribute between a CDATA xml structure, but instead will escape all the special characters that you place inside the CDATA.</p>
<div>
<div>
<pre><span style="color: #0000ff">&lt;?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">=&quot;1.0&quot;</span>?<span style="color: #0000ff">&gt;</span></pre>
<pre><span style="color: #0000ff">&lt;</span><span style="color: #800000">Example</span> <span style="color: #ff0000">xmlns:xsi</span><span style="color: #0000ff">=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></pre>
<pre>         <span style="color: #ff0000">xmlns:xsd</span><span style="color: #0000ff">=&quot;http://www.w3.org/2001/XMLSchema&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre>  <span style="color: #0000ff">&lt;</span><span style="color: #800000">RootNode</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">=&quot;xxxx&quot;</span> <span style="color: #ff0000">Version</span><span style="color: #0000ff">=&quot;1&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">CDataAttribute</span><span style="color: #0000ff">&gt;</span><span style="color: #ff0000">&amp;lt;</span>?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?<span style="color: #ff0000">&amp;gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">CDataAttribute</span><span style="color: #0000ff">&gt;</span></pre>
<pre>  <span style="color: #0000ff">&lt;/</span><span style="color: #800000">RootNode</span><span style="color: #0000ff">&gt;</span></pre>
<pre><span style="color: #0000ff">&lt;/</span><span style="color: #800000">Example</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p>As I really needed it to be placed inside a CData section, I searched on the Internet but did found a satisfying solution for this “problem”, but using the idea behind some of the articles (use <strong>XmlNode </strong>for the class CDataAttribute member instead of string) my solution was the following.</p>
<p>&#160;</p>
<p>First I generated my schema class without the <strong>CDataAttribute</strong>.</p>
<div>
<div>
<pre><span style="color: #0000ff">&lt;?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">=&quot;1.0&quot;</span> <span style="color: #ff0000">encoding</span><span style="color: #0000ff">=&quot;utf-8&quot;</span>?<span style="color: #0000ff">&gt;</span></pre>
<pre><span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:schema</span> <span style="color: #ff0000">id</span><span style="color: #0000ff">=&quot;Example&quot;</span> <span style="color: #ff0000">xmlns:xs</span><span style="color: #0000ff">=&quot;http://www.w3.org/2001/XMLSchema&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre>  <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:element</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;RootNode&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:complexType</span><span style="color: #0000ff">&gt;</span></pre>
<pre>      <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:sequence</span><span style="color: #0000ff">&gt;</span></pre>
<pre>        <span style="color: #008000">&lt;!-- NOTE: We could not generate a CDATA directly from XSD.</span></pre>
<pre><span style="color: #008000">             Generated by partial class --&gt;</span></pre>
<pre>        <span style="color: #008000">&lt;!--&lt;xs:element name=&quot;CDataAttribute&quot; type=&quot;xs:string&quot; minOccurs=&quot;0&quot;/&gt;--&gt;</span></pre>
<pre>      <span style="color: #0000ff">&lt;/</span><span style="color: #800000">xs:sequence</span><span style="color: #0000ff">&gt;</span></pre>
<pre>      <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:attribute</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;Type&quot;</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;xs:string&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<pre>      <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:attribute</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;Version&quot;</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;xs:string&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<pre>    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">xs:complexType</span><span style="color: #0000ff">&gt;</span></pre>
<pre>  <span style="color: #0000ff">&lt;/</span><span style="color: #800000">xs:element</span><span style="color: #0000ff">&gt;</span></pre>
<pre>  <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:element</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;Example&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:complexType</span><span style="color: #0000ff">&gt;</span></pre>
<pre>      <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:choice</span> <span style="color: #ff0000">minOccurs</span><span style="color: #0000ff">=&quot;0&quot;</span> <span style="color: #ff0000">maxOccurs</span><span style="color: #0000ff">=&quot;unbounded&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre>        <span style="color: #0000ff">&lt;</span><span style="color: #800000">xs:element</span> <span style="color: #ff0000">ref</span><span style="color: #0000ff">=&quot;RootNode&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<pre>      <span style="color: #0000ff">&lt;/</span><span style="color: #800000">xs:choice</span><span style="color: #0000ff">&gt;</span></pre>
<pre>    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">xs:complexType</span><span style="color: #0000ff">&gt;</span></pre>
<pre>  <span style="color: #0000ff">&lt;/</span><span style="color: #800000">xs:element</span><span style="color: #0000ff">&gt;</span></pre>
<pre><span style="color: #0000ff">&lt;/</span><span style="color: #800000">xs:schema</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p><p>Then I extended the partial generated class with my own implementation of the CDataAttribute.</p>
<div><strong></strong></p>
<div>
<pre><span style="color: #0000ff">using</span> System;</pre>
<pre><span style="color: #0000ff">using</span> System.Xml;</pre>
<pre>&#160;</pre>
<pre><span style="color: #0000ff">public</span> <span style="color: #0000ff">partial</span> <span style="color: #0000ff">class</span> RootNode</pre>
<pre>{</pre>
<pre>    <span style="color: #0000ff">private</span> XmlNode cDataAttributeField;</pre>
<pre>&#160;</pre>
<pre>    <span style="color: #008000">/// &lt;remarks/&gt;</span></pre>
<pre>    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]</pre>
<pre>    <span style="color: #0000ff">public</span> XmlNode CDataAttribute</pre>
<pre>    {</pre>
<pre>        get {<span style="color: #0000ff">return</span> <span style="color: #0000ff">this</span>.cDataAttributeField;}</pre>
<pre>        set {<span style="color: #0000ff">this</span>.cDataAttributeField = <span style="color: #0000ff">value</span>;}</pre>
<pre>    }</pre>
<pre>    </pre>
<pre>    <span style="color: #008000">/// &lt;summary&gt;</span></pre>
<pre>    <span style="color: #008000">/// Getter/Setter method for the CDATA document content field.</span></pre>
<pre>    <span style="color: #008000">/// Encapsulates the internal CDATA XmlNode</span></pre>
<pre>    <span style="color: #008000">/// &lt;/summary&gt;</span></pre>
<pre>    [System.Xml.Serialization.XmlIgnore()]</pre>
<pre>    <span style="color: #0000ff">public</span> String CDataAttributeByString</pre>
<pre>    {</pre>
<pre>        get </pre>
<pre>        { <span style="color: #008000">// Retrieves the content of the encapsulated CDATA</span></pre>
<pre>          <span style="color: #0000ff">return</span> cDataAttributeField.Value;</pre>
<pre>        }</pre>
<pre>&#160;</pre>
<pre>        set</pre>
<pre>        { <span style="color: #008000">// Encapsulate in a CDATA XmlNode</span></pre>
<pre>          XmlDocument xmlDocument = <span style="color: #0000ff">new</span> XmlDocument();</pre>
<pre>          <span style="color: #0000ff">this</span>.cDataAttributeField = xmlDocument.CreateCDataSection(<span style="color: #0000ff">value</span>);</pre>
<pre>        }</pre>
<pre>    }</pre>
<pre>}</pre>
</p></div>
</div>
<p>Note that I used a <strong>XMLNode</strong> for representing the class member that will be serialized. For setting this XMLNode I created a property (<strong>CDataAttributeByString</strong>) that receives a string and places in the XmlNode a <strong>CDataSection </strong>containing the received string value.</p>
<p>As so I only work with the CDataAttributeByString property, that is excluded from the serialization, and I let the .NET serializer use the CDataAttribute property for properly creating my CDataAttribute.</p>
<p>&#160;</p>
<p>Using the extended class, the serialized xml will now be:</p>
<div>
<div>
<pre><span style="color: #0000ff">&lt;?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">=&quot;1.0&quot;</span>?<span style="color: #0000ff">&gt;</span></pre>
<pre><span style="color: #0000ff">&lt;</span><span style="color: #800000">Example</span> <span style="color: #ff0000">xmlns:xsi</span><span style="color: #0000ff">=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></pre>
<pre>         <span style="color: #ff0000">xmlns:xsd</span><span style="color: #0000ff">=&quot;http://www.w3.org/2001/XMLSchema&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre>  <span style="color: #0000ff">&lt;</span><span style="color: #800000">RootNode</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">=&quot;xxxx&quot;</span> <span style="color: #ff0000">Version</span><span style="color: #0000ff">=&quot;1&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">CDataAttribute</span><span style="color: #0000ff">&gt;</span></pre>
<pre>        <span style="color: #0000ff">&lt;!</span>[CDATA[<span style="color: #0000ff">&lt;?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">=&quot;1.0&quot;</span> <span style="color: #ff0000">encoding</span><span style="color: #0000ff">=&quot;utf-8&quot;</span> ?<span style="color: #0000ff">&gt;</span>]]<span style="color: #0000ff">&gt;</span></pre>
<pre>    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">CDataAttribute</span><span style="color: #0000ff">&gt;</span></pre>
<pre>  <span style="color: #0000ff">&lt;/</span><span style="color: #800000">RootNode</span><span style="color: #0000ff">&gt;</span></pre>
<pre><span style="color: #0000ff">&lt;/</span><span style="color: #800000">Example</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p>&#160;</p>
<p>I hope that this can help some of you, and if you know a better solution please tell me.</p>
<p>I leave a sample project <a href="http://cid-9f675488377b7270.skydrive.live.com/self.aspx/Blog/CDataSerialization.7z" target="_blank">here</a>.</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2008/11/23/net-xml-serialization-of-cdata-attribute/">.NET XML Serialization of CDATA ATTRIBUTE</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/marcosilva/2008/11/23/net-xml-serialization-of-cdata-attribute/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Architect Forum 2008</title>
		<link>https://blogit.create.pt/marcosilva/2008/11/23/architect-forum-2008/</link>
					<comments>https://blogit.create.pt/marcosilva/2008/11/23/architect-forum-2008/#comments</comments>
		
		<dc:creator><![CDATA[Marco Silva]]></dc:creator>
		<pubDate>Sun, 23 Nov 2008 08:38:47 +0000</pubDate>
				<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Microsoft Azure]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/marcosilva/?p=71</guid>

					<description><![CDATA[<p>This week I participated in the Architect Forum 2008 in Portugal. The event was all about Cloud Computing and the agenda had two sessions: Microsoft’s Cloud Computing Platform : What it is and when to use it, by David Chappell Windows Azure, Padrões de Arquitectura e Caso de Uso, by João Pedro Martins, José António [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2008/11/23/architect-forum-2008/">Architect Forum 2008</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This week I participated in the <a href="http://www.microsoft.com/portugal/msdn/architectforum/default.mspx" target="_blank">Architect Forum</a> 2008 in Portugal. </p>
<p>The event was all about Cloud Computing and the agenda had two sessions:</p>
<ul>
<li>Microsoft’s Cloud Computing Platform : What it is and when to use it, by David Chappell </li>
<li>Windows Azure, Padrões de Arquitectura e Caso de Uso, by João Pedro Martins, José António Silva, Nuno Godinho </li>
</ul>
<p>The first session was more introductory and theoretical serving its purpose of presenting this new computing platform paradigm. What I also liked about it, was that the speaker focused not only on the Microsoft’s platform but on other platforms like the one’s from Amazon and Google, showing their differences and similarities, possible strengths and weaknesses.</p>
<p>Personally it seems that Microsoft’s platform given its “late appearance”&#160; (no one is really late) was given more thought and took advantage of the other previous experiments. But everything is right at the beginning and as so I expect everyone to be more or less “on-pair” when these platforms really take off.</p>
<p>The second session made the bridge from the theory to the practice by presenting scenarios where a cloud computing architecture “should” make sense and presenting advantages over “traditional” architectures. They showed a real case scenario with a expense reporting application running in the cloud platform of Microsoft that among other things made use of <a href="https://www.mesh.com/Welcome/default.aspx" target="_blank">Live Mesh</a>, <a href="http://www.microsoft.com/azure/netservices.mspx" target="_blank">.NET Services</a> (e.g. Service Bus) and <a href="http://www.microsoft.com/azure/sql.mspx" target="_blank">SQL Services</a> (e.g. Storage).</p>
<p>Overall I really enjoyed the event and look forward to dive deeper and experiment with these cloud platforms.</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2008/11/23/architect-forum-2008/">Architect Forum 2008</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/marcosilva/2008/11/23/architect-forum-2008/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Calling Excel (Web) Services from WCF</title>
		<link>https://blogit.create.pt/marcosilva/2008/08/01/calling-excel-web-services-from-wcf/</link>
					<comments>https://blogit.create.pt/marcosilva/2008/08/01/calling-excel-web-services-from-wcf/#respond</comments>
		
		<dc:creator><![CDATA[Marco Silva]]></dc:creator>
		<pubDate>Fri, 01 Aug 2008 19:37:42 +0000</pubDate>
				<category><![CDATA[Excel Services]]></category>
		<category><![CDATA[WebServices]]></category>
		<category><![CDATA[Office]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[WCF]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/marcosilva/?p=91</guid>

					<description><![CDATA[<p>Interfacing with Excel Services by means of WCF can be somewhat difficult at first and very subject to a trial and error experience. On my development environment I started by generating the Excel Web Services proxy using svcutil.exe. One of the key aspects for success started at this stage by telling svcutil to generate the [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2008/08/01/calling-excel-web-services-from-wcf/">Calling Excel (Web) Services from WCF</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Interfacing with Excel Services by means of WCF can be somewhat difficult at first and very subject to a trial and error experience.</p>
<p>On my development environment I started by generating the Excel Web Services proxy using <strong>svcutil.exe</strong>. One of the key aspects for success started at this stage by telling <strong>svcutil</strong> to generate the proxy using the <strong>XmlSerializer</strong> as opposed to the default <strong>DataContractSerializer</strong> (.NET 3.5). This is because whenever I tried to use the <strong>DataContractSerializer</strong> I would get serialization/deserialization errors.</p>
<p>The next step consisted on properly configuring the generated binding and endpoint. </p>
<p>For the binding I used the following configuration: </p>
<div>
<div>
<pre>&lt;binding name=<span style="color: #006080">&quot;ExcelServicesSoapBindingConfiguration&quot;</span></pre>
<pre>         closeTimeout=<span style="color: #006080">&quot;00:01:00&quot;</span> openTimeout=<span style="color: #006080">&quot;00:01:00&quot;</span></pre>
<pre>         receiveTimeout=<span style="color: #006080">&quot;00:01:00&quot;</span> sendTimeout=<span style="color: #006080">&quot;00:01:00&quot;</span></pre>
<pre>         allowCookies=<span style="color: #006080">&quot;false&quot;</span> bypassProxyOnLocal=<span style="color: #006080">&quot;false&quot;</span></pre>
<pre>         hostNameComparisonMode=<span style="color: #006080">&quot;StrongWildcard&quot;</span></pre>
<pre>         maxBufferSize=<span style="color: #006080">&quot;65536&quot;</span> maxBufferPoolSize=<span style="color: #006080">&quot;52428&quot;</span></pre>
<pre>         maxReceivedMessageSize=<span style="color: #006080">&quot;65536&quot;</span></pre>
<pre>         messageEncoding=<span style="color: #006080">&quot;Text&quot;</span> textEncoding=<span style="color: #006080">&quot;utf-8&quot;</span></pre>
<pre>         transferMode=<span style="color: #006080">&quot;Buffered&quot;</span> useDefaultWebProxy=<span style="color: #006080">&quot;true&quot;</span>&gt;</pre>
<pre>    &lt;readerQuotas maxDepth=<span style="color: #006080">&quot;32&quot;</span> maxStringContentLength=<span style="color: #006080">&quot;8192&quot;</span></pre>
<pre>                  maxArrayLength=<span style="color: #006080">&quot;16384&quot;</span> maxBytesPerRead=<span style="color: #006080">&quot;4096&quot;</span></pre>
<pre>                  maxNameTableCharCount=<span style="color: #006080">&quot;16384&quot;</span> /&gt;</pre>
<pre>    &lt;security mode=<span style="color: #006080">&quot;TransportCredentialOnly&quot;</span>&gt;</pre>
<pre>        &lt;transport clientCredentialType=<span style="color: #006080">&quot;Ntlm&quot;</span></pre>
<pre>                   proxyCredentialType=<span style="color: #006080">&quot;None&quot;</span> realm=<span style="color: #006080">&quot;&quot;</span> /&gt;</pre>
<pre>        &lt;message clientCredentialType=<span style="color: #006080">&quot;UserName&quot;</span> algorithmSuite=<span style="color: #006080">&quot;Default&quot;</span> /&gt;</pre>
<pre>    &lt;/security&gt;</pre>
<pre>&lt;/binding&gt;</pre>
</p></div>
</div>
<p>The relevant aspect here was the <strong>security</strong> with <strong>clientCredentialType </strong>set to <strong>Ntlm</strong>. Maybe this can be related with the authentication method that I choose for the SharePoint WebApplication/SiteCollection but I didn’t tested any other way.</p>
<p>The next part consisted on defining a <strong>Allow Impersonation</strong> behaviour. This behaviour as important in allowing the WCF service to act as the client while performing the operations with Excel Services (using the credentials of the client).</p>
<div>
<div>
<pre>&lt;endpointBehaviors&gt;</pre>
<pre>    &lt;!-- Impersonation endpoint behavior --&gt;</pre>
<pre>    &lt;behavior name=<span style="color: #006080">&quot;AllowImpersonationBehavior&quot;</span>&gt;</pre>
<pre>        &lt;clientCredentials&gt;</pre>
<pre>            &lt;windows allowedImpersonationLevel=<span style="color: #006080">&quot;Impersonation&quot;</span>/&gt;</pre>
<pre>        &lt;/clientCredentials&gt;                    </pre>
<pre>    &lt;/behavior&gt;</pre>
<pre>&lt;/endpointBehaviors&gt;</pre>
</p></div>
</div>
<p>This behaviour is used by the endpoint together with the binding configuration.</p>
<div>
<div>
<pre>&lt;endpoint address=<span style="color: #006080">&quot;http://localhost/_vti_bin/excelservice.asmx&quot;</span></pre>
<pre>    binding=<span style="color: #006080">&quot;basicHttpBinding&quot;</span></pre>
<pre>    bindingConfiguration=<span style="color: #006080">&quot;ExcelServicesSoapBindingConfiguration&quot;</span></pre>
<pre>    behaviorConfiguration=<span style="color: #006080">&quot;AllowImpersonationBehavior&quot;</span></pre>
<pre>    contract=<span style="color: #006080">&quot;Excel.WebServices.Proxy.ExcelServiceSoap&quot;</span></pre>
<pre>    name=<span style="color: #006080">&quot;ExcelServiceSoapEndpoint&quot;</span> /&gt;</pre>
</p></div>
</div>
<p>
<p>
<p>
<p><p>&#160;</p>
<p>With this WCF configuration I managed to successfully call and use the Excel Web Services, and also to call other SharePoint Web Services from WCF (e.g. lists service).</p>
<p>A final note is related with the <strong>readerQuotas </strong>and <strong>message sizes</strong> that you see in the binding configuration. These can be important depending on the amount of information that you exchange with the Web Services. Whenever you start to get deserialization errors or other “unexplainable” errors, always check these parameters because they can be smaller that the message sizes that you are trying to exchange. (It should be noted that this does not only apply to Excel Web Services but to services invocations in general).</p>
<p>&#160;</p>
<p>Please let me know of your own successes and experiences when using WCF with Excel or SharePoint Web Services.</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2008/08/01/calling-excel-web-services-from-wcf/">Calling Excel (Web) Services from WCF</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/marcosilva/2008/08/01/calling-excel-web-services-from-wcf/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Developing a WCF Service &#8211; Fault Exceptions AND FAULT Contracts</title>
		<link>https://blogit.create.pt/marcosilva/2008/05/18/developing-a-wcf-service-fault-exceptions-and-fault-contracts/</link>
					<comments>https://blogit.create.pt/marcosilva/2008/05/18/developing-a-wcf-service-fault-exceptions-and-fault-contracts/#respond</comments>
		
		<dc:creator><![CDATA[Marco Silva]]></dc:creator>
		<pubDate>Sun, 18 May 2008 12:59:54 +0000</pubDate>
				<category><![CDATA[WebServices]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Service]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/marcosilva/?p=111</guid>

					<description><![CDATA[<p>This next post about WCF will show how to integrate Fault Exceptions and Fault Contracts in your service. As written in MSDN Fault Exceptions are used for &#34;&#8230; mapping managed exception objects to SOAP fault objects and SOAP fault objects to managed exception objects &#8230;&#34;. This means that if you are looking for interoperability in [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2008/05/18/developing-a-wcf-service-fault-exceptions-and-fault-contracts/">Developing a WCF Service &#8211; Fault Exceptions AND FAULT Contracts</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This next post about WCF will show how to integrate Fault Exceptions and Fault Contracts in your service.</p>
<p>As written in MSDN Fault Exceptions are used for &quot;&#8230; mapping managed exception objects to SOAP fault objects and SOAP fault objects to managed exception objects &#8230;&quot;. This means that if you are looking for interoperability in your service development then you definitely should use this, because no Java client will understand a .NET exception.</p>
<p>You can read some more about it in this link <a href="http://msdn.microsoft.com/en-us/library/ms733721.aspx" target="_blank">Specifying and Handling Faults in Contracts and Services</a>.</p>
<p>So, when using Fault Exceptions (or SOAP Faults) you have two alternatives: </p>
<ul>
<li>Normal typed (or &quot;un-typed&quot;) &#8211; You throw a regular <font face="Courier New">FaultException <font face="Verdana">which only contains general information about the SOAP Fault</font></font></li>
<li>Strongly-typed &#8211; You define your own SOAP Fault object, which can contain any kind of information you want about the SOAP Fault</li>
</ul>
<p>Strongly-typed SOAP Faults are then used when you wish to give to the client some more information and context about the cause of the exception. They also couldn&#8217;t be much easier to define in WCF, because they are no more, no less than another Contract in the service definition, which are semantically called<strong> Fault Contracts</strong>.</p>
<p>As such, you define a Fault Contract in your service definition in the following way:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre><span style="color: #008000">/// &lt;summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre><span style="color: #008000">/// Strongly-typed fault.</span></pre>
<p><!--CRLF--></p>
<pre><span style="color: #008000">/// &lt;/summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre>[DataContract]</pre>
<p><!--CRLF--></p>
<pre><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ArgumentFault</pre>
<p><!--CRLF--></p>
<pre>{</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #cc6633">#region</span> Get / Set</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">/// &lt;summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">/// </span></pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">/// &lt;/summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre>    [DataMember]</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">public</span> String Operation { get; set; }</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">/// &lt;summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">/// </span></pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">/// &lt;/summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre>    [DataMember]</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">public</span> String Argument { get; set; }</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">/// &lt;summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">/// </span></pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">/// &lt;/summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre>    [DataMember]</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">public</span> String Message { get; set; }</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #cc6633">#endregion</span></pre>
<p><!--CRLF--></p>
<pre>}</pre>
<p><!--CRLF--></div>
</div>
<p>You then define that an operation can throw this type of fault contract by appending the following to your operation:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre>[FaultContract(<span style="color: #0000ff">typeof</span>(ArgumentFault))]</pre>
<p><!--CRLF--></p>
<pre>[OperationContract]</pre>
<p><!--CRLF--></p>
<pre>Customer GetCustomer(Int32 customerId);</pre>
<p><!--CRLF--></div>
</div>
<p>Now in the service implementation when you want to throw the defined fault contract you do like this:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre><span style="color: #0000ff">public</span> Customer GetCustomer(<span style="color: #0000ff">int</span> customerId)</pre>
<p><!--CRLF--></p>
<pre>{</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">if</span> (customerId &lt;= 0)</pre>
<p><!--CRLF--></p>
<pre>    { <span style="color: #008000">// Not possible</span></pre>
<p><!--CRLF--></p>
<pre>        <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> FaultException&lt;ArgumentFault&gt;(<span style="color: #0000ff">new</span> ArgumentFault()</pre>
<p><!--CRLF--></p>
<pre>        {</pre>
<p><!--CRLF--></p>
<pre>            Operation = MethodBase.GetCurrentMethod().Name,</pre>
<p><!--CRLF--></p>
<pre>            Argument = <span style="color: #006080">&quot;customerId&quot;</span>,</pre>
<p><!--CRLF--></p>
<pre>            Message = <span style="color: #006080">&quot;Argument must be greater than zero.&quot;</span></pre>
<p><!--CRLF--></p>
<pre>        });</pre>
<p><!--CRLF--></p>
<pre>    }</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">return</span> Customers.First(customer =&gt; </pre>
<p><!--CRLF--></p>
<pre>    {</pre>
<p><!--CRLF--></p>
<pre>        <span style="color: #0000ff">return</span> customer.Id == customerId;</pre>
<p><!--CRLF--></p>
<pre>    });</pre>
<p><!--CRLF--></p>
<pre>}</pre>
<p><!--CRLF--></div>
</div>
<p>This is better than just doing:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre><span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> FaultException(MethodBase.GetCurrentMethod().Name + </pre>
<p><!--CRLF--></p>
<pre>               <span style="color: #006080">&quot;: customerId - Argument must be greater than zero.&quot;</span>);</pre>
<p><!--CRLF--></div>
</div>
<p>&#160;</p>
<p>In the client application for catching this Fault Exception, you code should be:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre><span style="color: #0000ff">try</span></pre>
<p><!--CRLF--></p>
<pre>{    <span style="color: #008000">// Get customer</span></pre>
<p><!--CRLF--></p>
<pre>    Customer singleCustomer = proxy.GetCustomer(customers[0].Id);</pre>
<p><!--CRLF--></p>
<pre>    Console.WriteLine(<span style="color: #006080">&quot;SingleCustomer: Id - {0} / Name - {1}.&quot;</span>,</pre>
<p><!--CRLF--></p>
<pre>                singleCustomer.Id, singleCustomer.Name);</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">// Force fault</span></pre>
<p><!--CRLF--></p>
<pre>    singleCustomer = proxy.GetCustomer(0);</pre>
<p><!--CRLF--></p>
<pre>}</pre>
<p><!--CRLF--></p>
<pre><span style="color: #0000ff">catch</span> (FaultException&lt;ArgumentFault&gt; ex)</pre>
<p><!--CRLF--></p>
<pre>{</pre>
<p><!--CRLF--></p>
<pre>    Console.WriteLine(<span style="color: #006080">&quot;FaultException&lt;ArgumentFault&gt;: {0} - {1} - {2}&quot;</span>,</pre>
<p><!--CRLF--></p>
<pre>            ex.Detail.Operation, ex.Detail.Argument, ex.Detail.Message);</pre>
<p><!--CRLF--></p>
<pre>}</pre>
<p><!--CRLF--></p>
<pre><span style="color: #0000ff">catch</span> (FaultException ex)</pre>
<p><!--CRLF--></p>
<pre>{</pre>
<p><!--CRLF--></p>
<pre>    Console.WriteLine(<span style="color: #006080">&quot;FaultException: {0}&quot;</span>, ex.Message);</pre>
<p><!--CRLF--></p>
<pre>}</pre>
<p><!--CRLF--></div>
</div>
<p>&#160;</p>
<p>Again the full code is available <a href="http://t57huw.bay.livefilestore.com/y1pJpoyaXYtws7yTirA8cPK4GHb97yAnyjv0wrs-vnuqs5hAiolrr8VMkddvE8aQUShobrhPzZtmJID5oydxb8K3a5IWn8mkif0/SampleService.7z?download" target="_blank">here</a>: </p>
<p>&#160;</p>
<p><strong></strong></p>
<p><strong>Related List of articles</strong></p>
<p><a href="http://blogit.create.pt/blogs/marcosilva/archive/2008/03/30/Developing-a-WCF-Service.aspx" target="_blank">Developing a WCF Service</a></p>
<p><a href="http://blogit.create.pt/blogs/marcosilva/archive/2008/04/12/Developing-a-WCF-Service-_2D00_-Calling-the-hosted-service.aspx" target="_blank">Developing a WCF Service &#8211; Calling the hosted service</a></p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2008/05/18/developing-a-wcf-service-fault-exceptions-and-fault-contracts/">Developing a WCF Service &#8211; Fault Exceptions AND FAULT Contracts</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/marcosilva/2008/05/18/developing-a-wcf-service-fault-exceptions-and-fault-contracts/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Developing a WCF Service &#8211; Calling the hosted service</title>
		<link>https://blogit.create.pt/marcosilva/2008/04/12/developing-a-wcf-service-calling-the-hosted-service/</link>
					<comments>https://blogit.create.pt/marcosilva/2008/04/12/developing-a-wcf-service-calling-the-hosted-service/#respond</comments>
		
		<dc:creator><![CDATA[Marco Silva]]></dc:creator>
		<pubDate>Sat, 12 Apr 2008 14:03:54 +0000</pubDate>
				<category><![CDATA[WebServices]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Service]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/marcosilva/?p=131</guid>

					<description><![CDATA[<p>In the first part of this topic, I showed you how to develop a WCF service. In this next part I will show how to implement a client application that calls the exposed service methods, and how to make some enhancements to your service hosting. Ok, so he already have built and deployed our service [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2008/04/12/developing-a-wcf-service-calling-the-hosted-service/">Developing a WCF Service &#8211; Calling the hosted service</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In the first <a href="http://blogit.create.pt/blogs/marcosilva/archive/2008/03/30/Developing-a-WCF-Service.aspx">part</a> of this topic, I showed you how to develop a WCF service. In this next part I will show how to implement a client application that calls the exposed service methods, and how to make some enhancements to your service hosting.</p>
<p>Ok, so he already have built and deployed our service (either self-hosted, or in IIS for example), and by using a web browser we can see the service welcome page. Now, to call the service methods we must create a client proxy, and to do this we can use the Visual Studio <strong>Add Web Reference</strong>, which automatically creates the proxy, or we can use the command line <strong>svcutil </strong>to manually create the proxy. I prefer to do it manually because I like to control things like the generated proxy class namespace.</p>
<p>For example purposes, I created a Console Application that I called <strong>Tests.SampleService</strong>. There I created a batch file for calling the <strong>svcutil</strong> with my own parameters, with something similar to this:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre>svcutil %SERVICE_URL% /namespace:*,%NAMESPACE% /d:%OUT_DIR% /out:%OUT_FILE%</pre>
<p><!--CRLF--></div>
</div>
<p>With the service running, I executed the batch file and svcutil generated two files:</p>
<ul>
<li><strong>output.config</strong> &#8211; Contains the WCF runtime configurations for calling the service (&lt;system.serviceModel&gt;) </li>
<li><strong>Sample.Service.Proxy.cs </strong>&#8211; Contains the service proxy class, and any other classes exposed by the service </li>
</ul>
<p>The contents of the <strong>output.config </strong>should be placed in the console application <strong>App.Config </strong>(if you prefer you can just rename the file). </p>
<p>In your console application main file you can place code like the following:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre><span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args)</pre>
<p><!--CRLF--></p>
<pre>{</pre>
<p><!--CRLF--></p>
<pre>   Console.WriteLine(<span style="color: #006080">&quot;Press any key to start&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre>   Console.ReadLine();</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>   <span style="color: #008000">// Build the service proxy object</span></pre>
<p><!--CRLF--></p>
<pre>   ServiceClient proxy = <span style="color: #0000ff">new</span> ServiceClient();</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>   <span style="color: #008000">// Call service methods</span></pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>   <span style="color: #008000">// Get total number of customers</span></pre>
<p><!--CRLF--></p>
<pre>   Int32 totalCustomers = proxy.GetTotalNumberOfCustomers();</pre>
<p><!--CRLF--></p>
<pre>   Console.WriteLine(<span style="color: #006080">&quot;Total Customers: {0}&quot;</span>, totalCustomers);</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>   <span style="color: #008000">// Get list of customers</span></pre>
<p><!--CRLF--></p>
<pre>   List&lt;Customer&gt; customers = <span style="color: #0000ff">new</span> List&lt;Customer&gt;(proxy.GetCustomers());</pre>
<p><!--CRLF--></p>
<pre>   <span style="color: #0000ff">foreach</span> (Customer customer <span style="color: #0000ff">in</span> customers)</pre>
<p><!--CRLF--></p>
<pre>   {</pre>
<p><!--CRLF--></p>
<pre>       Console.WriteLine(<span style="color: #006080">&quot;Customers&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre>       Console.WriteLine(<span style="color: #006080">&quot;Customer: Id - {0} / Name - {1}.&quot;</span>, customer.Id, customer.Name);</pre>
<p><!--CRLF--></p>
<pre>   }</pre>
<p><!--CRLF--></p>
<pre>            </pre>
<p><!--CRLF--></p>
<pre>   <span style="color: #008000">// Get customer</span></pre>
<p><!--CRLF--></p>
<pre>   Customer singleCustomer = proxy.GetCustomer(customers[0].Id);</pre>
<p><!--CRLF--></p>
<pre>   Console.WriteLine(<span style="color: #006080">&quot;SingleCustomer: Id - {0} / Name - {1}.&quot;</span>, singleCustomer.Id, singleCustomer.Name);</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>   Console.WriteLine(<span style="color: #006080">&quot;Press any key to exit&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre>   Console.ReadLine();</pre>
<p><!--CRLF--></p>
<pre>}</pre>
<p><!--CRLF--></div>
</div>
<p>You are know ready to start your service and use your client application to call the service methods.</p>
<p>&#160;</p>
<h2></h2>
<h2>Service Host Enhancements</h2>
<p>Regarding the self service hosting there are some steps that you can do to make it more robust to errors and faults. Two of these changes are:</p>
<ul>
<li>Subscribe the service host <strong>Faulted </strong>event </li>
<li>Subscribe the service host <strong>Unknown Message Received </strong>event </li>
</ul>
<p>This should be done before opening our service hosting, and the new <strong>StartServiceHost </strong>method should look like this:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre><span style="color: #008000">/// &lt;summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre><span style="color: #008000">/// Creates the service host</span></pre>
<p><!--CRLF--></p>
<pre><span style="color: #008000">/// &lt;/summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre><span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> StartServiceHost()</pre>
<p><!--CRLF--></p>
<pre>{</pre>
<p><!--CRLF--></p>
<pre>    Logger.Info(<span style="color: #006080">&quot;StartServiceHost: Starting service hosting...&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">// Create service host</span></pre>
<p><!--CRLF--></p>
<pre>    _serviceHost = <span style="color: #0000ff">new</span> ServiceHost(<span style="color: #0000ff">typeof</span>(SampleService.Service));</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">// Subscribe to the Faulted event of the service host</span></pre>
<p><!--CRLF--></p>
<pre>    _serviceHost.Faulted += <span style="color: #0000ff">new</span> EventHandler(FaultHandler);</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">// Subscribe to the Unknown message received event of the service host</span></pre>
<p><!--CRLF--></p>
<pre>    _serviceHost.UnknownMessageReceived += <span style="color: #0000ff">new</span> EventHandler&lt;UnknownMessageReceivedEventArgs&gt;(UnknownMessageHandler);</pre>
<p><!--CRLF--></p>
<pre>    </pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">try</span></pre>
<p><!--CRLF--></p>
<pre>    { <span style="color: #008000">// Open service host</span></pre>
<p><!--CRLF--></p>
<pre>        _serviceHost.Open();</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>        Logger.Info(<span style="color: #006080">&quot;StartServiceHost: Service hosting success.&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre>    }</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">catch</span> (Exception ex)</pre>
<p><!--CRLF--></p>
<pre>    {</pre>
<p><!--CRLF--></p>
<pre>        Logger.Fatal(<span style="color: #006080">&quot;StartServiceHost: Could not start service hosting.&quot;</span>, ex);</pre>
<p><!--CRLF--></p>
<pre>    }            </pre>
<p><!--CRLF--></p>
<pre>}</pre>
<p><!--CRLF--></div>
</div>
<p>&#160;</p>
<p>The event handler&#8217;s code can be:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre><span style="color: #008000">/// &lt;summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre><span style="color: #008000">/// Fault error event handler</span></pre>
<p><!--CRLF--></p>
<pre><span style="color: #008000">/// &lt;/summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre><span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> FaultHandler(Object sender, EventArgs e)</pre>
<p><!--CRLF--></p>
<pre>{</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">// Examine the properties of the service host</span></pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">// Log reason for fault</span></pre>
<p><!--CRLF--></p>
<pre>    Logger.Error(<span style="color: #006080">&quot;FaultHandler: Host Fault occured. Aborting and restarting the hosting&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">// Abort the service (Could use Close, but a service in this state does not responde to requests, and Close takes more time)</span></pre>
<p><!--CRLF--></p>
<pre>    _serviceHost.Abort();</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">// Re-start service host</span></pre>
<p><!--CRLF--></p>
<pre>    StartServiceHost();</pre>
<p><!--CRLF--></p>
<pre>}</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre><span style="color: #008000">/// &lt;summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre><span style="color: #008000">/// Unknown message event handler</span></pre>
<p><!--CRLF--></p>
<pre><span style="color: #008000">/// &lt;/summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre><span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> UnknownMessageHandler(Object sender, UnknownMessageReceivedEventArgs e)</pre>
<p><!--CRLF--></p>
<pre>{</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">// Log the unknown message</span></pre>
<p><!--CRLF--></p>
<pre>    Logger.Warn(<span style="color: #006080">&quot;UnknownMessageHandler: Unknown Message Received&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre>}</pre>
<p><!--CRLF--></div>
</div>
<p>&#160;</p>
<p>Take into attention that when the service host goes into a <strong>Faulted </strong>state, it stops servicing requests. This is why in the <strong>FaultHandler</strong> we abort the service host and open it again.</p>
<p>You can make a quick test of the event handlers by introducing in your web browser the following address: <a href="http://localhost:8080/SampleService/Service.svc">http://localhost:8080/SampleService/Service.svc</a>.</p>
<p>This makes the service receive an <strong>unknown</strong> message and the corresponding event handler is called.</p>
<p>I leave <a href="http://t57huw.bay.livefilestore.com/y1pJpoyaXYtws7yTirA8cPK4GHb97yAnyjv0wrs-vnuqs5hAiolrr8VMkddvE8aQUShobrhPzZtmJID5oydxb8K3a5IWn8mkif0/SampleService.7z?download" target="_blank">here</a> the complete Visual Studio solution.</p>
<p>&#160;</p>
<h2>Related list of articles:</h2>
<p><a href="http://blogit.create.pt/blogs/marcosilva/archive/2008/03/30/Developing-a-WCF-Service.aspx" target="_blank">Developing a WCF Service</a></p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2008/04/12/developing-a-wcf-service-calling-the-hosted-service/">Developing a WCF Service &#8211; Calling the hosted service</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/marcosilva/2008/04/12/developing-a-wcf-service-calling-the-hosted-service/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Developing a WCF Service</title>
		<link>https://blogit.create.pt/marcosilva/2008/03/30/developing-a-wcf-service/</link>
					<comments>https://blogit.create.pt/marcosilva/2008/03/30/developing-a-wcf-service/#respond</comments>
		
		<dc:creator><![CDATA[Marco Silva]]></dc:creator>
		<pubDate>Sun, 30 Mar 2008 20:20:42 +0000</pubDate>
				<category><![CDATA[WebServices]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Service]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/marcosilva/?p=151</guid>

					<description><![CDATA[<p>It is typical to have projects based on a client-server architecture where the server publishes a number of services. These services are normally Web-Services, and as so are available through the SOAP protocol. The &#34;traditional&#34; way of implementing these services is by using ASMX, but nowadays you have another great alternative &#8211; Windows Communication Foundation [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2008/03/30/developing-a-wcf-service/">Developing a WCF Service</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>It is typical to have projects based on a client-server architecture where the server publishes a number of services. These services are normally Web-Services, and as so are available through the SOAP protocol.</p>
<p>The &quot;traditional&quot; way of implementing these services is by using ASMX, but nowadays you have another great alternative &#8211; Windows Communication Foundation (WCF) in .NET 3.5.</p>
<p>This, being my first WCF post, intends to demonstrate that developing a simple WCF service is as easy as doing it in ASMX, while allowing us to make future evolutions on our service architecture to support everything that WCF makes available.</p>
<h2>&#160;</h2>
<p>Well, as always you start out by creating a new Visual Studio project. I chose to use the existent project template &#8216;WCF Service Library&#8217; (but some of you may want to start by an empty project 😀 ).</p>
<p>This creates a project with the following list of files (I changed the service name to &#8216;Service&#8217;, and I only list the WCF most important files:</p>
<ul>
<li><strong>IService.cs</strong> &#8211; Describes the exposed service interface. This is where we will namely define the <strong>[ServiceContract]</strong> (The service itself) and the <strong>[OperationContract]</strong>&#8216;s (The operations exposed by the service). More information in <a href="http://msdn2.microsoft.com/en-us/library/ms729746.aspx" target="_blank">Designing and Implementing Services</a>. </li>
<li><strong>Service.cs </strong>&#8211; The service interface implementation class. This is where the actual code of the service operations will be contained. More information in <a href="http://msdn2.microsoft.com/en-us/library/ms733764.aspx" target="_blank">Implementing Service Contracts</a>. </li>
</ul>
<p>There is another important file, <strong>App.Config</strong>, that contains the service configuration (e.g. service listening url), but I will refer to this file later when talking about the service hosting (creates the service and controls its context and lifetime). More information in <a href="http://msdn2.microsoft.com/en-us/library/ms730158.aspx" target="_blank">Hosting Services</a>.</p>
<p>So a simple service contract could be:</p>
<div>
<div>
<pre>[ServiceContract]</pre>
<pre><span style="color: #0000ff">public</span> <span style="color: #0000ff">interface</span> IService</pre>
<pre>{</pre>
<pre>    [OperationContract]</pre>
<pre>    Int32 GetTotalNumberOfCustomers();</pre>
<pre>&#160;</pre>
<pre>    [OperationContract]</pre>
<pre>    Customer GetCustomer(Int32 customerId);</pre>
<pre>&#160;</pre>
<pre>    [OperationContract]</pre>
<pre>    List&lt;Customer&gt; GetCustomers();        </pre>
<pre>}</pre>
</p></div>
</div>
<p>This code defines a service contract (<strong>IService</strong>) that exposes three operations (operation functionality is self explanatory):</p>
<ul>
<li><strong>GetTotalNumberOfCustomers</strong> </li>
<li><strong>GetCustomer</strong> </li>
<li><strong>GetCustomers</strong> </li>
</ul>
<p>You will notice that in the code we are referring a custom class that is not contained anywhere in the service contract, that is the <strong>Customer </strong>class. This class must be described in WCF like a <strong>[DataContract] </strong>because it is a new, complex data type that WCF does not know how to serialize. More information in <a href="http://msdn2.microsoft.com/en-us/library/ms733127.aspx" target="_blank">Using Data Contracts</a>.</p>
<p>Our data contract is defined like this:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre>[DataContract]</pre>
<p><!--CRLF--></p>
<pre><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> Customer</pre>
<p><!--CRLF--></p>
<pre>{</pre>
<p><!--CRLF--></p>
<pre>    [DataMember]</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">public</span> Int32 Id { get; set; }</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    [DataMember]</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">public</span> String Name { get; set; }</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">public</span> Customer()</pre>
<p><!--CRLF--></p>
<pre>    {</pre>
<p><!--CRLF--></p>
<pre>        Id = 0;</pre>
<p><!--CRLF--></p>
<pre>        Name = String.Empty;</pre>
<p><!--CRLF--></p>
<pre>    }</pre>
<p><!--CRLF--></p>
<pre>}</pre>
<p><!--CRLF--></div>
</div>
<p>One important aspect of data contracts are the <strong>[DataMember]</strong> properties, that are properties to be exposed by the data contract.</p>
<p>&#160;</p>
<p>At this point we are ready to implement our service contract, that for this example is very simple, and obviously not production code:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> Service : IService</pre>
<p><!--CRLF--></p>
<pre>{</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">private</span> List&lt;Customer&gt; Customers = <span style="color: #0000ff">new</span> List&lt;Customer&gt;()</pre>
<p><!--CRLF--></p>
<pre>    {</pre>
<p><!--CRLF--></p>
<pre>        <span style="color: #0000ff">new</span> Customer() {Id = 1, Name = <span style="color: #006080">&quot;Customer1&quot;</span> },</pre>
<p><!--CRLF--></p>
<pre>        <span style="color: #0000ff">new</span> Customer() {Id = 2, Name = <span style="color: #006080">&quot;Customer2&quot;</span> },</pre>
<p><!--CRLF--></p>
<pre>        <span style="color: #0000ff">new</span> Customer() {Id = 3, Name = <span style="color: #006080">&quot;Customer3&quot;</span> }</pre>
<p><!--CRLF--></p>
<pre>    };</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> GetTotalNumberOfCustomers()</pre>
<p><!--CRLF--></p>
<pre>    {</pre>
<p><!--CRLF--></p>
<pre>        <span style="color: #0000ff">return</span> Customers.Count;</pre>
<p><!--CRLF--></p>
<pre>    }</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">public</span> Customer GetCustomer(<span style="color: #0000ff">int</span> customerId)</pre>
<p><!--CRLF--></p>
<pre>    {</pre>
<p><!--CRLF--></p>
<pre>        <span style="color: #0000ff">return</span> Customers.First(customer =&gt; </pre>
<p><!--CRLF--></p>
<pre>        {</pre>
<p><!--CRLF--></p>
<pre>            <span style="color: #0000ff">return</span> customer.Id == customerId;</pre>
<p><!--CRLF--></p>
<pre>        });</pre>
<p><!--CRLF--></p>
<pre>    }</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">public</span> List&lt;Customer&gt; GetCustomers()</pre>
<p><!--CRLF--></p>
<pre>    {</pre>
<p><!--CRLF--></p>
<pre>        <span style="color: #0000ff">return</span> Customers;</pre>
<p><!--CRLF--></p>
<pre>    }</pre>
<p><!--CRLF--></p>
<pre>}</pre>
<p><!--CRLF--></div>
</div>
<p>&#160;</p>
<p>Our service is now ready to be hosted and this is one of the beauties of WCF in the sense that the hosting environment can be a:</p>
<ul>
<li>Windows/WPF Application </li>
<li>Console application </li>
<li>Windows Service </li>
<li>IIS/WAS </li>
</ul>
<p>Each of them has advantages and disadvantages an again I refer you to <a href="http://msdn2.microsoft.com/en-us/library/ms730158.aspx" target="_blank">Hosting Services</a> (look at the Choosing a Hosting Environment table). Take into attention that the Service Library that you develop is always the same regardless of the hosting environment that you choose, and even if you choose one hosting environment now, you can choose another later and easily change between them.</p>
<p>For developing/debugging purposes I normally choose for hosting a simple WPF application with just two buttons (Start and Stop), where I place the following code (the <strong>Logger</strong> object is of log4net <strong>ILog</strong> type):</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre><span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> StartServiceHost()</pre>
<p><!--CRLF--></p>
<pre>{</pre>
<p><!--CRLF--></p>
<pre>    Logger.Info(<span style="color: #006080">&quot;StartServiceHost: Starting service hosting...&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">// Create service host</span></pre>
<p><!--CRLF--></p>
<pre>    _serviceHost = <span style="color: #0000ff">new</span> ServiceHost(<span style="color: #0000ff">typeof</span>(SampleService.Service));</pre>
<p><!--CRLF--></p>
<pre>    </pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">try</span></pre>
<p><!--CRLF--></p>
<pre>    { <span style="color: #008000">// Open service host</span></pre>
<p><!--CRLF--></p>
<pre>        _serviceHost.Open();</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>        Logger.Info(<span style="color: #006080">&quot;StartServiceHost: Service hosting success.&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre>    }</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">catch</span> (Exception ex)</pre>
<p><!--CRLF--></p>
<pre>    {</pre>
<p><!--CRLF--></p>
<pre>        Logger.Fatal(<span style="color: #006080">&quot;StartServiceHost: Could not start service hosting.&quot;</span>, ex);</pre>
<p><!--CRLF--></p>
<pre>    }            </pre>
<p><!--CRLF--></p>
<pre>}</pre>
<p><!--CRLF--></div>
</div>
<div>&#160;</div>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre><span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> StopServiceHost()</pre>
<p><!--CRLF--></p>
<pre>{</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #008000">// Close service host</span></pre>
<p><!--CRLF--></p>
<pre>    _serviceHost.Close();</pre>
<p><!--CRLF--></p>
<pre>}</pre>
<p><!--CRLF--></div>
</div>
<p>Now, you just have to properly configure the application configuration file (remember we talked about it earlier), and you are ready to test your service. Note that I configured the service hosting all thru the <strong>App.Config </strong>file and as simple and compatible as possible with a ASMX (e.g. Basic HTTP binding).</p>
<p>Note: I will differ binding&#8217;s and other configuration explanations to another time. Right now I just want you to see how you can get started with WCF.</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre>&lt;configuration&gt;</pre>
<p><!--CRLF--></p>
<pre>    &lt;system.serviceModel&gt;</pre>
<p><!--CRLF--></p>
<pre>        &lt;services&gt;</pre>
<p><!--CRLF--></p>
<pre>        &lt;service behaviorConfiguration=<span style="color: #006080">&quot;SampleService.Service.Behavior&quot;</span> name=<span style="color: #006080">&quot;SampleService.Service&quot;</span>&gt;</pre>
<p><!--CRLF--></p>
<pre>            &lt;host&gt;</pre>
<p><!--CRLF--></p>
<pre>                &lt;baseAddresses&gt;</pre>
<p><!--CRLF--></p>
<pre>                    &lt;add baseAddress=<span style="color: #006080">&quot;http://localhost:8080/SampleService&quot;</span>/&gt;</pre>
<p><!--CRLF--></p>
<pre>                &lt;/baseAddresses&gt;</pre>
<p><!--CRLF--></p>
<pre>            &lt;/host&gt;</pre>
<p><!--CRLF--></p>
<pre>            &lt;endpoint    address=<span style="color: #006080">&quot;/Service.svc&quot;</span></pre>
<p><!--CRLF--></p>
<pre>                        binding=<span style="color: #006080">&quot;basicHttpBinding&quot;</span></pre>
<p><!--CRLF--></p>
<pre>                        name=<span style="color: #006080">&quot;IService_BasicHttpEndpoint&quot;</span></pre>
<p><!--CRLF--></p>
<pre>                        contract=<span style="color: #006080">&quot;SampleService.IService&quot;</span></pre>
<p><!--CRLF--></p>
<pre>                        bindingConfiguration=<span style="color: #006080">&quot;IService_BasicHttpBindingConfiguration&quot;</span>&gt;</pre>
<p><!--CRLF--></p>
<pre>            &lt;/endpoint&gt;</pre>
<p><!--CRLF--></p>
<pre>        &lt;/service&gt;</pre>
<p><!--CRLF--></p>
<pre>    &lt;/services&gt;</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    &lt;behaviors&gt;</pre>
<p><!--CRLF--></p>
<pre>        &lt;serviceBehaviors&gt;</pre>
<p><!--CRLF--></p>
<pre>            &lt;behavior name=<span style="color: #006080">&quot;SampleService.Service.Behavior&quot;</span>&gt;</pre>
<p><!--CRLF--></p>
<pre>                &lt;!-- To avoid disclosing metadata information, </pre>
<p><!--CRLF--></p>
<pre>      set the <span style="color: #0000ff">value</span> below to <span style="color: #0000ff">false</span> and remove the metadata endpoint above before deployment --&gt;</pre>
<p><!--CRLF--></p>
<pre>                &lt;serviceMetadata httpGetEnabled=<span style="color: #006080">&quot;True&quot;</span>/&gt;</pre>
<p><!--CRLF--></p>
<pre>                &lt;!-- To receive exception details <span style="color: #0000ff">in</span> faults <span style="color: #0000ff">for</span> debugging purposes, </pre>
<p><!--CRLF--></p>
<pre>      set the <span style="color: #0000ff">value</span> below to <span style="color: #0000ff">true</span>.  Set to <span style="color: #0000ff">false</span> before deployment </pre>
<p><!--CRLF--></p>
<pre>      to avoid disclosing exception information --&gt;</pre>
<p><!--CRLF--></p>
<pre>                &lt;serviceDebug includeExceptionDetailInFaults=<span style="color: #006080">&quot;True&quot;</span> /&gt;                </pre>
<p><!--CRLF--></p>
<pre>            &lt;/behavior&gt;</pre>
<p><!--CRLF--></p>
<pre>        &lt;/serviceBehaviors&gt;</pre>
<p><!--CRLF--></p>
<pre>    &lt;/behaviors&gt;</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    &lt;bindings&gt;</pre>
<p><!--CRLF--></p>
<pre>        &lt;basicHttpBinding&gt;</pre>
<p><!--CRLF--></p>
<pre>            &lt;!-- Service host binding configuration --&gt;</pre>
<p><!--CRLF--></p>
<pre>            &lt;binding name=<span style="color: #006080">&quot;IService_BasicHttpBindingConfiguration&quot;</span></pre>
<p><!--CRLF--></p>
<pre>                             maxBufferSize=<span style="color: #006080">&quot;65536&quot;</span> maxBufferPoolSize=<span style="color: #006080">&quot;52428&quot;</span></pre>
<p><!--CRLF--></p>
<pre>                             maxReceivedMessageSize=<span style="color: #006080">&quot;65536&quot;</span> transferMode=<span style="color: #006080">&quot;Buffered&quot;</span>&gt;            </pre>
<p><!--CRLF--></p>
<pre>                &lt;readerQuotas maxDepth=<span style="color: #006080">&quot;32&quot;</span> maxArrayLength=<span style="color: #006080">&quot;16384&quot;</span></pre>
<p><!--CRLF--></p>
<pre>                                            maxBytesPerRead=<span style="color: #006080">&quot;4096&quot;</span> maxNameTableCharCount=<span style="color: #006080">&quot;16384&quot;</span></pre>
<p><!--CRLF--></p>
<pre>                                            maxStringContentLength=<span style="color: #006080">&quot;8192&quot;</span>/&gt;</pre>
<p><!--CRLF--></p>
<pre>            &lt;/binding&gt;</pre>
<p><!--CRLF--></p>
<pre>        &lt;/basicHttpBinding&gt;</pre>
<p><!--CRLF--></p>
<pre>    &lt;/bindings&gt;</pre>
<p><!--CRLF--></p>
<pre>    </pre>
<p><!--CRLF--></p>
<pre>&lt;/system.serviceModel&gt;</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>&lt;configuration&gt;</pre>
<p><!--CRLF--></div>
</div>
<p>If you now run the WPF application and point your browser to <a href="http://localhost:8080/SampleService" target="_blank">http://localhost:8080/SampleService</a> you should see a welcome page telling you that you have created a service.</p>
<p>You are now ready to start writing a client application that will call your service operation contracts (my next post will be about this part, but you have everything you need in the service welcome page).</p>
<p>To end, I just want to show you how easy it is to change the hosting environment to IIS for example. For hosting in IIS you just have to follow these steps:</p>
<ul>
<li>Create a new web application in IIS </li>
<li>Place the presented <strong>App.Config</strong> &lt;system.serviceModel&gt; tag in a <strong>Web.Config</strong> file </li>
<li>Deploy the service library assembly to the web application bin directory </li>
<li>Create a special file, in my example called <strong>Service.svc</strong>, with the following content: </li>
</ul>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre>&lt;%@ServiceHost language=<span style="color: #006080">&quot;C#&quot;</span> Debug=<span style="color: #006080">&quot;true&quot;</span></pre>
<p><!--CRLF--></p>
<pre>                             Service=<span style="color: #006080">&quot;SampleService.Service&quot;</span>%&gt;</pre>
<p><!--CRLF--></p>
<pre>&lt;%@Assembly Name=<span style="color: #006080">&quot;SampleService&quot;</span> %&gt;</pre>
<p><!--CRLF--></div>
</div>
<p>The only different part in hosting in IIS is just the need to create the <strong>.svc</strong> file that tells IIS which service should be instantiated.</p>
<p>Again, if you point your browser to <a href="http://localhost:8080/SampleService/Service.svc" target="_blank">http://localhost:8080/SampleService/Service.svc</a> you should see the same page as before.</p>
<p>I hope that this can get you started in WCF more easily and I will try to show what other capabilities WCF provides in some next posts.</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2008/03/30/developing-a-wcf-service/">Developing a WCF Service</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/marcosilva/2008/03/30/developing-a-wcf-service/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Log4net Initialization/Configuration alternatives</title>
		<link>https://blogit.create.pt/marcosilva/2008/02/24/log4net-initializationconfiguration-alternatives/</link>
					<comments>https://blogit.create.pt/marcosilva/2008/02/24/log4net-initializationconfiguration-alternatives/#respond</comments>
		
		<dc:creator><![CDATA[Marco Silva]]></dc:creator>
		<pubDate>Sun, 24 Feb 2008 11:24:06 +0000</pubDate>
				<category><![CDATA[Debug]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Log]]></category>
		<category><![CDATA[Framework]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/marcosilva/?p=171</guid>

					<description><![CDATA[<p>In a previous post where I talked about using log4net I used one of the alternative ways to initialize and configure the logging services. This post will summarize these alternatives. &#160; 1. Programmatic initialization The programmatic initialization should be done somewhere in your code. This was the type of initialization used on the first post [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2008/02/24/log4net-initializationconfiguration-alternatives/">Log4net Initialization/Configuration alternatives</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In a previous <a href="http://blogit.create.pt/blogs/marcosilva/archive/2007/07/29/Using-log4net-logging-services.aspx">post</a> where I talked about using log4net I used one of the alternative ways to initialize and configure the logging services.</p>
<p>This post will summarize these alternatives.</p>
<p>&#160;</p>
<h2>1. Programmatic initialization</h2>
<p><font size="1"><span style="font-family: courier new,courier"></span></font></p>
<p>The programmatic initialization should be done somewhere in your code.</p>
<p>This was the type of initialization used on the first post and its code is something like this.</p>
<p><font size="1"><span style="font-family: courier new,courier">using log4net;</span></font></p>
<p><font size="1"><span style="font-family: courier new,courier">using log4net.Config;</span></font></p>
<p><font size="1"><span style="font-family: courier new,courier"></span></font></p>
<p><font size="1"><span style="font-family: courier new,courier">public class MyApp </span>      <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">{</span>       <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&#160;&#160;&#160; private static readonly ILog log = LogManager.GetLogger(typeof(MyApp));</span>       <br style="font-family: courier new,courier">      <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&#160;&#160;&#160; static void Main(string[] args) </span>      <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&#160;&#160;&#160; {</span>       <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&#160;&#160;&#160;&#160;&#160;&#160;&#160; // BasicConfigurator replaced with XmlConfigurator.</span>       <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&#160;&#160;&#160;&#160;&#160;&#160;&#160; XmlConfigurator.Configure(new System.IO.FileInfo(args[0]));</span></font></p>
<p><font size="1"><span style="font-family: courier new,courier"></span></font><font size="1"></font></p>
<p><font size="1"></font></p>
<p><font size="1"><font size="1">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font face="Courier New">&#160; log.Info(&quot;Entering application.&quot;);</font></font></font></p>
<p><font size="1"><span style="font-family: courier new,courier">&#160;&#160;&#160; }</span></font></p>
<p><font size="1"><span style="font-family: courier new,courier"></span></font><font size="1"><span style="font-family: courier new,courier">} </span></font></p>
<p><font size="1"><span style="font-family: courier new,courier"></span></font></p>
<h2>2. Assembly attribute initialization</h2>
<p>The assembly attribute initialization does not imply the inclusion of any code in your application. Instead, you just have to place an assembly level attribute in some file of your assembly. This way your code could be:</p>
<p><font size="1"><span style="font-family: courier new,courier">using log4net;</span></font></p>
<p><font face="Courier New" size="1">[assembly: log4net.Config.XmlConfigurator()]</font></p>
<p><font size="1"><span style="font-family: courier new,courier">public class MyApp </span>      <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">{</span>       <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&#160;&#160;&#160; private static readonly ILog log = LogManager.GetLogger(typeof(MyApp));</span>       <br style="font-family: courier new,courier">      <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&#160;&#160;&#160; static void Main(string[] args) </span>      <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&#160;&#160;&#160; {</span>       <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><font face="Courier New">log.Info(&quot;Entering application.&quot;);<span style="font-family: courier new,courier"></span></font>       <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&#160;&#160;&#160; }</span>       <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">} </span></font></p>
<p>&#160;</p>
<p>The assembly level attribute by itself does not mean a instruction to initialize the logging framework. Instead, the logging framework is initialized by the first call that is made to log4net (in the example the <font face="Courier New" size="1">log.Info<font face="Verdana" size="2">) initialized. This means that when using assembly attributes you should make a logging call as soon as possible and before calling any other external assembly.</font></font></p>
<p>&#160;</p>
<p>Finally, if you are using logger objects defined per-class, a simple way to define a logger object that enables it to be copy-pasted in a very simple way is to do:</p>
<p><font face="Courier New" size="1">private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);</font></p>
<p><p>&#160;</p>
<p>This instruction uses reflection for determining the class type name that will be used in the logging messages.</p>
<p>For more information please refer to the log4net <a href="http://logging.apache.org/log4net" target="_blank">homepage</a>.</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2008/02/24/log4net-initializationconfiguration-alternatives/">Log4net Initialization/Configuration alternatives</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/marcosilva/2008/02/24/log4net-initializationconfiguration-alternatives/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SharePoint Associating a Workflow to a list</title>
		<link>https://blogit.create.pt/marcosilva/2007/12/10/sharepoint-associating-a-workflow-to-a-list/</link>
					<comments>https://blogit.create.pt/marcosilva/2007/12/10/sharepoint-associating-a-workflow-to-a-list/#respond</comments>
		
		<dc:creator><![CDATA[Marco Silva]]></dc:creator>
		<pubDate>Mon, 10 Dec 2007 05:07:00 +0000</pubDate>
				<category><![CDATA[Object Model]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[SharePoint]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/marcosilva/?p=191</guid>

					<description><![CDATA[<p>Continuing from my last post, one thing that you also may want to do when programmatically creating a list is associating a workflow with a given configuration (e.g. Approval workflow when a new item is created in a document library).In the SharePoint interface we can do this association very easily but if you want to [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2007/12/10/sharepoint-associating-a-workflow-to-a-list/">SharePoint Associating a Workflow to a list</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Continuing from my last post, one thing that you also may want to do when programmatically creating a list is associating a workflow with a given configuration (e.g. Approval workflow when a new item is created in a document library).<br />In the SharePoint interface we can do this association very easily but if you want to do it using the object model there are a few steps that you should have into consideration.</p>
<p>First what we need to create is a <font face="courier new,courier">SPWorkflowAssociation </font>more specifically <font face="courier new,courier">SPWorkflowAssociation.CreateListAssociation</font>. For this we need to give information like:</p>
<ul>
<li><font face="courier new,courier">Workflow template</font> &ndash; Template to use for the workflow (e.g. Approval);</li>
<li><font face="courier new,courier">Workflow Title </font>&ndash; Name of the workflow;</li>
<li><font face="courier new,courier">Workflow task list</font> &ndash; Name of the workflow task list (should be based on the Tasks list template);</li>
<li><font face="courier new,courier">Workflow history list </font>&ndash; Name of the workflow history list (should be based on the Workflow History list template).</li>
</ul>
<p>After creating the <font face="courier new,courier">SPWorkflowAssociation </font>we can set general workflow parameters that are nothing more than configurations available in all workflow templates:</p>
<ul>
<li><font face="courier new,courier">AllowManual </font>&ndash; Allow manual start of the workflow;</li>
<li><font face="courier new,courier">AutoStartCreate </font>&ndash; Auto start the workflow on item creation;</li>
<li><font face="courier new,courier">AutoStartChange </font>&ndash; Auto start the workflow on item change;</li>
<li><font face="courier new,courier">AssociationData </font>&ndash; Association data to be passed to the workflow instance.</li>
</ul>
<p>The key parameter here is the <font face="courier new,courier">AssociationData </font>that contains workflow template specific configurations to be passed to the corresponding workflow instances. For example referring to the out-of-box Approval workflow, its association data is something like this (in XML because the Approval workflow uses an InfoPath form for its configuration page):</p>
<p><font face="courier new,courier">&lt;my:myFields xml:lang=&quot;en-us&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;xmlns:my=&quot;http://schemas.microsoft.com/office/infopath/2003/myXSD&quot;&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;my:Reviewers&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;my:Person&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;my:DisplayName&gt;Administrator&lt;/my:DisplayName&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;my:AccountId&gt;Administrator&lt;/my:AccountId&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;my:AccountType&gt;User&lt;/my:AccountType&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/my:Person&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/my:Reviewers&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;my:CC&gt;&lt;/my:CC&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:DueDate xsi:nil=&quot;true&quot;&gt;&lt;/my:DueDate&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:Description xsi:nil=&quot;true&quot;&gt;&lt;/my:Description&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:Title&gt;&lt;/my:Title&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:DefaultTaskType&gt;1&lt;/my:DefaultTaskType&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:CreateTasksInSerial&gt;true&lt;/my:CreateTasksInSerial&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:AllowDelegation&gt;false&lt;/my:AllowDelegation&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:AllowChangeRequests&gt;true&lt;/my:AllowChangeRequests&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:StopOnAnyReject xsi:nil=&quot;true&quot;&gt;&lt;/my:StopOnAnyReject&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:WantedTasks xsi:nil=&quot;true&quot;&gt;&lt;/my:WantedTasks&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:SetMetadataOnSuccess&gt;false&lt;/my:SetMetadataOnSuccess&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:MetadataSuccessField&gt;&lt;/my:MetadataSuccessField&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:MetadataSuccessValue&gt;&lt;/my:MetadataSuccessValue&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:ApproveWhenComplete&gt;false&lt;/my:ApproveWhenComplete&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:TimePerTaskVal xsi:nil=&quot;true&quot;&gt;&lt;/my:TimePerTaskVal&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:TimePerTaskType xsi:nil=&quot;true&quot;&gt;&lt;/my:TimePerTaskType&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:Voting&gt;false&lt;/my:Voting&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:MetadataTriggerField&gt;&lt;/my:MetadataTriggerField&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:MetadataTriggerValue&gt;&lt;/my:MetadataTriggerValue&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:InitLock&gt;true&lt;/my:InitLock&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:MetadataStop&gt;false&lt;/my:MetadataStop&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:ItemChangeStop&gt;false&lt;/my:ItemChangeStop&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:GroupTasks&gt;true&lt;/my:GroupTasks&gt;<br />&lt;/my:myFields&gt;&nbsp;</font></p>
<p>As you can see this association data contains the rest of the configuration parameters regarding the workflow template and in the case of the Approval workflow it contains something as important as the Approvers list (Reviewers).</p>
<p>With this you have all the information that is needed to correctly configure and associate an workflow to a list. Just don&rsquo;t forget in the end to do something like <font face="courier new,courier">SPList.AddWorkflowAssociation(SPWorkflowAssociation)</font>.</p>
<p>I leave you here an example method to accomplish what was described.</p>
<p><font face="courier new,courier">public SPWorkflowAssociation AddListWorkflowAssociation(SPWeb parentWeb, SPList parentList, String title, String workflowTemplateName, String workflowTaskListName, String workflowHistoryListName,Boolean workflowAllowManualStart, Boolean workflowAutoStartOnCreate, Boolean workflowAutoStartOnChange, String workflowAssociationData)<br />{<br />&nbsp;&nbsp;&nbsp; // Search for workflow template in site<br />&nbsp;&nbsp;&nbsp; foreach (SPWorkflowTemplate workflowTemplate in parentWeb.WorkflowTemplates)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (workflowTemplate.Name == workflowTemplateName)<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { // Found</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Check is task and history lists already exist<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; SPList taskList;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; SPList historyList;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; try<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; taskList = parentWeb.Lists[workflowTaskListName];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; catch (System.ArgumentException)<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; { // Does not exist in site. Add<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; taskList = SPHelper.AddList(parentWeb, workflowTaskListName, &quot;Task list for workflow.&quot;, &quot;Tasks&quot;, false);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; try<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; historyList = parentWeb.Lists[workflowHistoryListName];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; catch (System.ArgumentException)<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; { // Does not exist in site. Add<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; historyList = SPHelper.AddList(parentWeb, workflowHistoryListName, &quot;History list for workflow.&quot;, &quot;Workflow History&quot;, false);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; // Create workflow list association<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; SPWorkflowAssociation workflowAssociation = SPWorkflowAssociation.CreateListAssociation(workflowTemplate, title, taskList, historyList);</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; // Set workflow parameters<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; workflowAssociation.AllowManual = workflowAllowManualStart;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; workflowAssociation.AutoStartCreate = workflowAutoStartOnCreate;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; workflowAssociation.AutoStartChange = workflowAutoStartOnChange;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; workflowAssociation.AssociationData = workflowAssociationData;</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; // Add workflow to list<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; workflowAssociation = parentList.AddWorkflowAssociation(workflowAssociation);<br />&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; workflowAssociation.Enabled = true;</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; // Return workflow object<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; return workflowAssociation;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp; // Error if reach here<br />&nbsp;&nbsp;&nbsp; return null;</font></p>
<p><font face="courier new,courier">}</font><br />&nbsp;</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2007/12/10/sharepoint-associating-a-workflow-to-a-list/">SharePoint Associating a Workflow to a list</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/marcosilva/2007/12/10/sharepoint-associating-a-workflow-to-a-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SharePoint 2007 basics – Add a Folder</title>
		<link>https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-folder/</link>
					<comments>https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-folder/#respond</comments>
		
		<dc:creator><![CDATA[Marco Silva]]></dc:creator>
		<pubDate>Thu, 01 Nov 2007 09:40:00 +0000</pubDate>
				<category><![CDATA[Object Model]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[SharePoint]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/marcosilva/?p=211</guid>

					<description><![CDATA[<p>Folders can be added under a list or under another folder and the way of adding in each case is very similar. Below another example of sample functions.&#160;public SPFolder AddFolder(SPList parentList, String title){&#160;&#160;&#160; // Enable folder creation on the list&#160;&#160;&#160; parentList.EnableFolderCreation = true;&#160; &#160;&#160;&#160; // Add folder&#160;&#160;&#160; SPListItem listItem = parentList.Folders.Add(&#34;&#34;, SPFileSystemObjectType.Folder);&#160;&#160;&#160; listItem[&#34;Name&#34;] = title; [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-folder/">SharePoint 2007 basics – Add a Folder</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'">Folders can be added under a list or under another<br />
folder and the way of adding in each case is very similar. Below another<br />
example of sample functions.</span><br />&nbsp;<br /><font face="courier new,courier" size="1">public SPFolder AddFolder(SPList parentList, String title)<br />{<br />&nbsp;&nbsp;&nbsp; // Enable<br />
folder creation on the list<br />&nbsp;&nbsp;&nbsp; parentList.EnableFolderCreation<br />
= true;&nbsp;</font></p>
<p><font face="courier new,courier" size="1">&nbsp;&nbsp;&nbsp; // Add folder<br />&nbsp;&nbsp;&nbsp; SPListItem<br />
listItem = parentList.Folders.Add(&quot;&quot;, SPFileSystemObjectType.Folder);<br />&nbsp;&nbsp;&nbsp; listItem[&quot;Name&quot;]<br />
= title;</font></p>
<p><font face="courier new,courier" size="1">&nbsp;&nbsp; // Update<br /></font><font face="courier new,courier" size="1">&nbsp;&nbsp; listItem.Update();</font></p>
<p><font face="courier new,courier" size="1"></font></p>
<p><font face="courier new,courier" size="1"></font><font face="courier new,courier" size="1">&nbsp;&nbsp; // Return<br /></font><font face="courier new,courier" size="1">&nbsp;&nbsp; return<br />
listItem.Folder;<br />}</font></p>
<p><font face="courier new,courier" size="1">public SPFolder<br />
AddFolder(SPFolder folder, String title)<br />{<br />&nbsp;&nbsp;&nbsp; // Add<br />&nbsp;&nbsp;&nbsp; SPFolder<br />
newFolder = folder.SubFolders.Add(title);&nbsp;</font></p>
<p><font face="courier new,courier" size="1">&nbsp;&nbsp;&nbsp; // Return<br />&nbsp;&nbsp;&nbsp; return<br />
newFolder;<br />}</font></p>
<p><font face="courier new,courier" size="1">&nbsp;</font></p>
<p><font face="courier new,courier" size="1">&nbsp;</font></p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-folder/">SharePoint 2007 basics – Add a Folder</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-folder/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
