<?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>WebServices Archives - Blog IT</title>
	<atom:link href="https://blogit.create.pt/category/integration/webservices/feed/" rel="self" type="application/rss+xml" />
	<link>https://blogit.create.pt/category/integration/webservices/</link>
	<description>Create IT blogger community</description>
	<lastBuildDate>Thu, 10 Jan 2019 14:19:07 +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>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>At Your Service: Performance Considerations for Making Web Service Calls from ASPX Pages</title>
		<link>https://blogit.create.pt/raulribeiro/2006/07/06/at-your-service-performance-considerations-for-making-web-service-calls-from-aspx-pages/</link>
					<comments>https://blogit.create.pt/raulribeiro/2006/07/06/at-your-service-performance-considerations-for-making-web-service-calls-from-aspx-pages/#respond</comments>
		
		<dc:creator><![CDATA[Raúl Ribeiro]]></dc:creator>
		<pubDate>Thu, 06 Jul 2006 02:05:00 +0000</pubDate>
				<category><![CDATA[WebServices]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/raulribeiro/?p=2041</guid>

					<description><![CDATA[<p>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service07222003.asp</p>
<p>The post <a href="https://blogit.create.pt/raulribeiro/2006/07/06/at-your-service-performance-considerations-for-making-web-service-calls-from-aspx-pages/">At Your Service: Performance Considerations for Making Web Service Calls from ASPX Pages</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service07222003.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service07222003.asp</a></p>
<p>The post <a href="https://blogit.create.pt/raulribeiro/2006/07/06/at-your-service-performance-considerations-for-making-web-service-calls-from-aspx-pages/">At Your Service: Performance Considerations for Making Web Service Calls from ASPX Pages</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/raulribeiro/2006/07/06/at-your-service-performance-considerations-for-making-web-service-calls-from-aspx-pages/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Web services Contract-First, for real</title>
		<link>https://blogit.create.pt/raulribeiro/2005/05/17/web-services-contract-first-for-real/</link>
					<comments>https://blogit.create.pt/raulribeiro/2005/05/17/web-services-contract-first-for-real/#respond</comments>
		
		<dc:creator><![CDATA[Raúl Ribeiro]]></dc:creator>
		<pubDate>Tue, 17 May 2005 17:06:00 +0000</pubDate>
				<category><![CDATA[WebServices]]></category>
		<category><![CDATA[Soa]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/raulribeiro/?p=2921</guid>

					<description><![CDATA[<p>WSCF 0.4 &#8220;Web services Contract-First, for real&#8221;   We featured the WsContractFirst Add-In in an earlier post, but Christian let me know they have a much improved release of WSCF now. Check out the walkthrough for complete details.   New Features in v0.4 (compared to v0.3): WSDL creation wizard Abstracts away WSDL details. WSDL conforms [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/raulribeiro/2005/05/17/web-services-contract-first-for-real/">Web services Contract-First, for real</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div><b>WSCF 0.4 &#8220;Web services Contract-First, for real&#8221;</b> </div>
<div> </div>
<div>We featured the WsContractFirst Add-In in an <a href="http://blogs.msdn.com/powertoys/archive/2004/09/15/229993.aspx">earlier post</a>, but <a href="http://weblogs.asp.net/cweyer/">Christian</a> let me know they have a much improved release of WSCF now. </div>
<div>Check out the <a href="http://www.thinktecture.com/Resources/Software/WSContractFirst/WSCF04Walkthrough1.html">walkthrough for complete details</a>. </div>
<div> </div>
<div>New Features in v0.4 (compared to v0.3): </div>
<li>WSDL creation wizard
</li>
<li>Abstracts away WSDL details.
</li>
<li>WSDL conforms to WS-I BP 1.0 recommendations.
</li>
<li>Only Doc/literal support
</li>
<li>One portType per WSDL.
</li>
<li>One binding per WSDL.
</li>
<li>One header per message.
</li>
<li>No fault support.
</li>
<li>Documentation items.
</li>
<li>Right-click message .XSD file in VS.NET to start wizard.
</li>
<li>No round-tripping, i.e. currently one-way WSDL generation only.
</li>
<li>Command line interface (wscf.exe), for including the code generation features in batch files or build environments.
</li>
<li>Intrinsic support for RPC/literal WSDL descriptions.
</li>
<li>Adds task list items for important steps to take care of after code generation.
</li>
<li>Should run with VS.NET 2002. </li>
<div> </div>
<div><font size="4"><u>Blog Review</u> </font></div>
<div> </div>
<div><a href="http://blogs.msdn.com/smguest/archive/2004/12/09/278972.aspx">Via smguest</a>: &#8220;In short, this tool rocks. It works as follows: You create an XSD using your favorite editor (for example, Visual Studio .NET or XMLSpy) and import it into your Visual Studio .NET project. Right clicking on the XSD in Solution Explorer brings up an option to generate a WSDL file. &#8220;</div>
<p>The post <a href="https://blogit.create.pt/raulribeiro/2005/05/17/web-services-contract-first-for-real/">Web services Contract-First, for real</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/raulribeiro/2005/05/17/web-services-contract-first-for-real/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
