<?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>Idea Manglar &#187; WCF</title>
	<atom:link href="http://blog.manglar.com/category/wcf/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.manglar.com</link>
	<description>{ideas}</description>
	<lastBuildDate>Tue, 08 Jun 2010 08:02:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to use SSL in a WCF service</title>
		<link>http://blog.manglar.com/how-to-use-ssl-in-a-wcf-service/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=how-to-use-ssl-in-a-wcf-service</link>
		<comments>http://blog.manglar.com/how-to-use-ssl-in-a-wcf-service/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 20:46:09 +0000</pubDate>
		<dc:creator>Germán Medina</dc:creator>
				<category><![CDATA[Tech Recipes]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://blog.manglar.com/?p=199</guid>
		<description><![CDATA[1. Enable SSL configuration on your site
2. Set your binding security mode to Transport.
3. Set you service behavior serviceAuthorization PrincipalPermissionMode to None.

public class ServiceHostFactory : WebServiceHostFactory
    {
        protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        {
            ServiceHost host = new ServiceHost(typeof(Services), baseAddresses);
            host.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.None;
            ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(IServices), new WebHttpBinding(WebHttpSecurityMode.Transport), &#34;&#34;);
            endpoint.Behaviors.Add(new WebHttpBehaviorEx());
            return host;
        ]]></description>
			<content:encoded><![CDATA[<p>1. Enable SSL configuration on your site<br />
2. Set your binding security mode to Transport.<br />
3. Set you service behavior serviceAuthorization PrincipalPermissionMode to None.</p>
<pre class="brush: csharp; wrap-lines: false;">
public class ServiceHostFactory : WebServiceHostFactory
    {
        protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        {
            ServiceHost host = new ServiceHost(typeof(Services), baseAddresses);
            host.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.None;
            ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(IServices), new WebHttpBinding(WebHttpSecurityMode.Transport), &quot;&quot;);
            endpoint.Behaviors.Add(new WebHttpBehaviorEx());
            return host;
        }
    }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.manglar.com/how-to-use-ssl-in-a-wcf-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to publish WCF services using IIS6</title>
		<link>http://blog.manglar.com/how-to-publish-wcf-services-using-iis6/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=how-to-publish-wcf-services-using-iis6</link>
		<comments>http://blog.manglar.com/how-to-publish-wcf-services-using-iis6/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 01:44:55 +0000</pubDate>
		<dc:creator>Germán Medina</dc:creator>
				<category><![CDATA[Tech Recipes]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Webservices]]></category>

		<guid isPermaLink="false">http://blog.manglar.com/?p=197</guid>
		<description><![CDATA[1. C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis –i
2. C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe –i
3. Do all the things you normally do on IIS7, you are all set.
]]></description>
			<content:encoded><![CDATA[<p>1. C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis –i<br />
2. C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe –i<br />
3. Do all the things you normally do on IIS7, you are all set.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.manglar.com/how-to-publish-wcf-services-using-iis6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to go beyond PUT and DELETE limitations on RESTful Scenarios</title>
		<link>http://blog.manglar.com/how-to-go-beyond-put-and-delete-limitations-on-restful-scenarios/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=how-to-go-beyond-put-and-delete-limitations-on-restful-scenarios</link>
		<comments>http://blog.manglar.com/how-to-go-beyond-put-and-delete-limitations-on-restful-scenarios/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 04:38:33 +0000</pubDate>
		<dc:creator>Germán Medina</dc:creator>
				<category><![CDATA[Tech Recipes]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>

		<guid isPermaLink="false">http://blog.manglar.com/?p=186</guid>
		<description><![CDATA[One of the biggest problems you will have while implementing RESTful services is that most of today’s browsers and firewalls will not allow PUT and DELETE requests. An easy way to fix this is to add a custom HTTP header to your post requests and send the real method in there. Since Google is using ]]></description>
			<content:encoded><![CDATA[<p>One of the biggest problems you will have while implementing RESTful services is that most of today’s browsers and firewalls will not allow PUT and DELETE requests. An easy way to fix this is to add a custom HTTP header to your post requests and send the real method in there. Since Google is using “X-HTTP-Method-Override” it looks like a smart choice to follow that pattern and use it too.</p>
<p>This simple jquery code shows how to do it in the client side:</p>
<pre class="brush: jscript;">
$.ajax({
    type: &quot;POST&quot;,
    url: serviceURL,
    data: &quot;data&quot;,
    success: function(data, textStatus) { alert(&quot;success&quot;); },
    error: function(xhr, status, error) { alert(&quot;error&quot;); },
    beforeSend: function(xhr) { xhr.setRequestHeader(&quot;X-HTTP-Method-Override&quot;, &quot;DELETE&quot;); }
});
</pre>
<p>This C# code shows how to use the custom header in a WCF server:</p>
<pre class="brush: csharp;">
public String PostProxy(String data)
{
    switch (HttpContext.Current.Request.Headers[&quot;X-HTTP-Method-Override&quot;])
    {
        case &quot;PUT&quot;: return Add(data);
        case &quot;DELETE&quot;: return Delete(data);
        default: return Update(data);
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.manglar.com/how-to-go-beyond-put-and-delete-limitations-on-restful-scenarios/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Big files transfer using WCF services</title>
		<link>http://blog.manglar.com/big-files-transfer-using-wcf-services/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=big-files-transfer-using-wcf-services</link>
		<comments>http://blog.manglar.com/big-files-transfer-using-wcf-services/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 22:15:43 +0000</pubDate>
		<dc:creator>Germán Medina</dc:creator>
				<category><![CDATA[Tech Recipes]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Webservices]]></category>

		<guid isPermaLink="false">http://blog.manglar.com/?p=178</guid>
		<description><![CDATA[If you need to receive files bigger than 4MB using WCF services you have to change the default configuration in your web.config file to allow the size required.

&#60;system.web&#62;
    &#60;httpRuntime maxRequestLength=&#34;131072&#34; /&#62;
&#60;/system.web&#62;

Note: this should work for any ASP application.
]]></description>
			<content:encoded><![CDATA[<p>If you need to receive files bigger than 4MB using WCF services you have to change the default configuration in your web.config file to allow the size required.</p>
<pre class="brush: xml;">
&lt;system.web&gt;
    &lt;httpRuntime maxRequestLength=&quot;131072&quot; /&gt;
&lt;/system.web&gt;
</pre>
<p>Note: this should work for any ASP application.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.manglar.com/big-files-transfer-using-wcf-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Declarative permissions for WCF services</title>
		<link>http://blog.manglar.com/declarative-permissions-for-wcf-services/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=declarative-permissions-for-wcf-services</link>
		<comments>http://blog.manglar.com/declarative-permissions-for-wcf-services/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 22:02:41 +0000</pubDate>
		<dc:creator>Germán Medina</dc:creator>
				<category><![CDATA[Tech Recipes]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Permissions]]></category>

		<guid isPermaLink="false">http://blog.manglar.com/?p=176</guid>
		<description><![CDATA[When you develop WCF services you might want to have some protected and unprotected methods on the same service. To do this you will need to do as follows.
Publish your service on an unprotected area of your site; change your web.config file to do it:

&#60;location path=&#34;services&#34;&#62;
    &#60;system.web&#62;
        &#60;authorization&#62;
            &#60;allow users=&#34;*&#34; /&#62;
        &#60;/authorization&#62;
    &#60;/system.web&#62;
&#60;/location&#62;

Add this line ]]></description>
			<content:encoded><![CDATA[<p>When you develop WCF services you might want to have some protected and unprotected methods on the same service. To do this you will need to do as follows.<br />
Publish your service on an unprotected area of your site; change your web.config file to do it:</p>
<pre class="brush: xml; wrap-lines: false;">
&lt;location path=&quot;services&quot;&gt;
    &lt;system.web&gt;
        &lt;authorization&gt;
            &lt;allow users=&quot;*&quot; /&gt;
        &lt;/authorization&gt;
    &lt;/system.web&gt;
&lt;/location&gt;
</pre>
<p>Add this line of code to your service constructor method:</p>
<pre class="brush: csharp; wrap-lines: false;">
public Service()
{
    Thread.CurrentPrincipal = HttpContext.Current.User;
}
</pre>
<p>Finally use declarative permissions on the service methods you want to protect:</p>
<pre class="brush: csharp; wrap-lines: false;">
[PrincipalPermission(SecurityAction.Demand)]
public String YourMethod()
{
    return String.Empty;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.manglar.com/declarative-permissions-for-wcf-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Los servicios Web de hoy (REST)</title>
		<link>http://blog.manglar.com/los-servicios-web-de-hoy-rest/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=los-servicios-web-de-hoy-rest</link>
		<comments>http://blog.manglar.com/los-servicios-web-de-hoy-rest/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 13:30:35 +0000</pubDate>
		<dc:creator>Germán Medina</dc:creator>
				<category><![CDATA[Concepts]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Webservices]]></category>

		<guid isPermaLink="false">http://blog.manglar.com/?p=118</guid>
		<description><![CDATA[Hace un par de años cuando trabajaba en un proyecto sobre el lenguaje de programación Python me encontré con el reto de integrar una aplicación con otra. Como era de esperarse, la respuesta inmediata fue usar webservices. En ese momento para hacer uso de este concepto tan obvio y tan común en nuestros días necesitábamos ]]></description>
			<content:encoded><![CDATA[<p>Hace un par de años cuando trabajaba en un proyecto sobre el lenguaje de programación Python me encontré con el reto de integrar una aplicación con otra. Como era de esperarse, la respuesta inmediata fue usar webservices. En ese momento para hacer uso de este concepto tan obvio y tan común en nuestros días necesitábamos emplear unas librerías hechas por un buen samaritano del desarrollo open source que no había tenido tiempo últimamente para actualizar su trabajo, no teníamos más opciones. El resultado, un tortuoso proceso hasta lograr una integración a medias y que estaba limitada por las posibilidades del lenguaje de programación que estábamos usando.<br />
Varios años después, me encontraba en una conferencia de desarrolladores y escuche por primera vez el concepto REST. Sonaba como una solución maravillosa, como esas cosas que son tan simples y tan obvias que uno no entiende como nadie pensó antes en ellas, y más aun, como nos pudimos meter en algún momento en problemas como el de la integración de la aplicación en Python.<br />
REST es otro estilo de arquitectura para desarrollo de aplicaciones a través de webservices, si, otro. Lo que hace que REST sea diferente es que es lo más neutral posible, solo hace uso de algo que ya todos hemos adoptado, la Web. Parece lógico, pero y acaso los demás webservices no usan la Web también? Si claro, pero para comunicar una aplicación con otras se han creado protocolos de comunicación nuevos (SOAP) sobre el protocolo ya existente, HTTP. REST solo usa HTTP, nada más. Pero si será posible que algo tan sencillo permita crear aplicaciones a gran escala como lo permite hoy en día SOAP? De acuerdo con Roy Fielding, uno de los creadores de la especificación de HTTP sí. REST (Representational State Transfer) predica la separación de capas, el no uso de estados (sesiones) y el aprovechamiento del cache que son características comunes en sistemas distribuidos. Los beneficios que se obtienen son interoperabilidad, evolución independiente, escalabilidad y mejoramiento del desempeño.<br />
La Web fue construida sobre HTTP, una interface uniforme e independiente de la tecnología usada, esta interface fue diseñada para que humanos y maquinas interactúen unos con otros a través de métodos elementales como GET, POST, PUT o DELETE (las acciones básicas de cualquier sistema de información). Los servicios REST usan esta única interface para hacer de la comunicación entre aplicaciones algo natural, eficiente y fácil de implementar. Hoy en día los grandes proveedores de aplicaciones y servicios Web han adoptado a REST como la plataforma fundamental para sus negocios. Facebook, Twitter, Microsoft y Google son algunos de los ejemplos más sobresalientes.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.manglar.com/los-servicios-web-de-hoy-rest/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to provide custom JSON exceptions from a WCF service</title>
		<link>http://blog.manglar.com/how-to-provide-custom-json-exceptions-from-as-wcf-service/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=how-to-provide-custom-json-exceptions-from-as-wcf-service</link>
		<comments>http://blog.manglar.com/how-to-provide-custom-json-exceptions-from-as-wcf-service/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 22:38:44 +0000</pubDate>
		<dc:creator>Germán Medina</dc:creator>
				<category><![CDATA[Tech Recipes]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Errors]]></category>
		<category><![CDATA[Exceptions]]></category>
		<category><![CDATA[JSON]]></category>

		<guid isPermaLink="false">http://blog.manglar.com/?p=86</guid>
		<description><![CDATA[In my last post I described a simple way to handle exceptions in WCF services (It might be helpful to read it before this one). Now I’d like to go a step further writing a solution to provide JSON exceptions. This approach is helpful for applications using pure JavaScript to connect to a WCF service. ]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://blog.manglar.com/?p=78/">last post</a> I described a simple way to handle exceptions in WCF services (It might be helpful to read it before this one). Now I’d like to go a step further writing a solution to provide JSON exceptions. This approach is helpful for applications using pure JavaScript to connect to a WCF service. For me it makes a lot of sense to have a service that transparently provides JSON responses with exception information instead of regular HTML or XML responses, which are very difficult to deal with using JavaScript.</p>
<p>First we need to create our Error class. This error class will contain all the attributes we define for our JSON Exception. This class will be serialized as JSON before sending it as response when an exception occurs.</p>
<pre class="brush: csharp;">
[DataContract]
public class AjaxError
{
    [DataMember]
    public int Code { get; set; }
    [DataMember]
    public String Message { get; set; }
}
</pre>
<p> Then we need to write our ErrorHandler class implementing IErrorHandler interface. In the ProvideFault method we will take care of the object serializing the response object and setting the response content type and status. You may notice that we are always setting the response status as BadRequest, this is just a personal decision, you can set it as InternalServerError o any other status you decide.</p>
<pre class="brush: csharp;">
public class ErrorHandlerEx : IErrorHandler
{
    public bool HandleError(Exception error)
    {
        return true;
    }

    public void ProvideFault(Exception exception, MessageVersion version, ref Message message)
    {
        AjaxError error = new AjaxError();
        error.Code = 1;
        error.Message = exception.Message;
        message = Message.CreateMessage(version, &quot;&quot;, error, new DataContractJsonSerializer(error.GetType()));
        var wbf = new WebBodyFormatMessageProperty(WebContentFormat.Json);
        message.Properties.Add(WebBodyFormatMessageProperty.Name, wbf);
        WebOperationContext.Current.OutgoingResponse.ContentType = &quot;application/json&quot;;
        WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.InternalServerError;
    }
}
</pre>
<p> After that we create a behavior inheriting from WebHttpBehavior and in the AddServerErrorHandlers class we remove the existing error handlers and add ours.</p>
<pre class="brush: csharp;">
public class WebHttpBehaviorEx : WebHttpBehavior
{
    protected override void AddServerErrorHandlers(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
    {
        endpointDispatcher.ChannelDispatcher.ErrorHandlers.Clear();
        endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(new ErrorHandlerEx());
    }
}
</pre>
<p> Now we need to write our own service factory inheriting from WebServiceHostFactory and in the CreateServiceHost method we add our custom behavior to the endpoint.</p>
<pre class="brush: csharp;">
public class ServiceHostFactory : WebServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        ServiceHost host = new ServiceHost(typeof(Services), baseAddresses);
        ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(IServices), new WebHttpBinding(), &quot;&quot;);
        endpoint.Behaviors.Add(new WebHttpBehaviorEx());
        return host;
    }
}
</pre>
<p> Finally we need to set our Service factory in the Factory attribute of the ServiceHost tag for our Service Markup.</p>
<pre class="brush: csharp;">
&lt;%@ ServiceHost
        Language=&quot;C#&quot;
        Debug=&quot;true&quot;
        Service=&quot;Services&quot;
        CodeBehind=&quot;Services.svc.cs&quot;
        Factory=&quot;ServiceHostFactory&quot;
%&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.manglar.com/how-to-provide-custom-json-exceptions-from-as-wcf-service/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to take care of unhandled exceptions in WCF Services</title>
		<link>http://blog.manglar.com/how-to-take-care-of-unhandled-exceptions-in-wcf-services/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=how-to-take-care-of-unhandled-exceptions-in-wcf-services</link>
		<comments>http://blog.manglar.com/how-to-take-care-of-unhandled-exceptions-in-wcf-services/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 20:19:56 +0000</pubDate>
		<dc:creator>Germán Medina</dc:creator>
				<category><![CDATA[Tech Recipes]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Errors]]></category>
		<category><![CDATA[Exceptions]]></category>

		<guid isPermaLink="false">http://blog.manglar.com/?p=78</guid>
		<description><![CDATA[When developing web services using WCF it’s considered a good practice to take care of unhandled exceptions. In this post I’ll explain an easy way to log your WCF unhandled errors and create a custom message.
First you will need to create a class that inherits from Attribute and implements IServiceBehavior and IErrorHandler interfaces.  Inheritance ]]></description>
			<content:encoded><![CDATA[<p>When developing web services using WCF it’s considered a good practice to take care of unhandled exceptions. In this post I’ll explain an easy way to log your WCF unhandled errors and create a custom message.</p>
<p>First you will need to create a class that inherits from Attribute and implements IServiceBehavior and IErrorHandler interfaces.  Inheritance from Attribute will allow us to use our new class as metadata for our service. IServiceBehavior interface makes our new class a custom extension for a service and IErrorHandler will give us control over service faults. As you can think we will be creating a new service behavior that handles errors and will be assigned to our service as a metadata attribute. This is the code for our custom error handler:</p>
<pre class="brush: csharp;">
public class ErrorHandlerAttribute : Attribute, IServiceBehavior, IErrorHandler
{
    public bool HandleError(Exception e)
    {
        EventLog log = new EventLog();
        log.Source = &quot;Your Application Name&quot;;
        log.WriteEntry(e.Message + &quot;\n&quot; + e.StackTrace, EventLogEntryType.Error);
        return true;
    }

    public void ProvideFault(Exception error,
        MessageVersion ver,
        ref System.ServiceModel.Channels.Message msg)
    {
        FaultException fe = new FaultException(&quot;Your Custom Error&quot;);
        MessageFault fault = fe.CreateMessageFault();
        msg = System.ServiceModel.Channels.Message.CreateMessage(ver, fault, null);
    }

    public void AddBindingParameters(ServiceDescription serviceDescription,
        ServiceHostBase serviceHostBase,
        Collection&lt;ServiceEndpoint&gt; endpoints,
        BindingParameterCollection bindingParameters)
    {

    }

    public void ApplyDispatchBehavior(ServiceDescription serviceDescription,
        ServiceHostBase serviceHostBase)
    {

    }

    public void Validate(ServiceDescription serviceDescription,
        ServiceHostBase serviceHostBase)
    {

    }
}
</pre>
<p>The AddBindingParameters, ApplyDispatchBehavior and Validate methods will need no implementation. We just need to take care of HandleError method for logging and ProvideFault method to create our custom error message.</p>
<p> After that all you need to do is annotate your service class with the error handler:</p>
<pre class="brush: csharp;">
[ErrorHandler]
public class Service : IService
{
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.manglar.com/how-to-take-care-of-unhandled-exceptions-in-wcf-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Forms Based Authentication (FBA) on a desktop application in C#</title>
		<link>http://blog.manglar.com/fba-on-desktop-applications/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=fba-on-desktop-applications</link>
		<comments>http://blog.manglar.com/fba-on-desktop-applications/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 22:22:41 +0000</pubDate>
		<dc:creator>Germán Medina</dc:creator>
				<category><![CDATA[Tech Recipes]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[FBA]]></category>
		<category><![CDATA[Forms Based Authentication]]></category>

		<guid isPermaLink="false">http://manglar.wordpress.com/?p=49</guid>
		<description><![CDATA[To use FBA on a desktop client will be necessary to make a first request to the server and create the authentication cookie. This cookie will be used on the next requests to receive permission from the server to access protected resources imitating the browser’s behavior.
First we need to write a server side method that ]]></description>
			<content:encoded><![CDATA[<p>To use FBA on a desktop client will be necessary to make a first request to the server and create the authentication cookie. This cookie will be used on the next requests to receive permission from the server to access protected resources imitating the browser’s behavior.<br />
First we need to write a server side method that receives the login and password information, does the authentication task and creates the authentication cookie:</p>
<pre class="brush: csharp;">
public bool Authenticate(String login, String password)
{
    if (Membership.ValidateUser(login, password))
    {
        System.Web.Security.FormsAuthentication.SetAuthCookie(login, false);
        return true;
    }
    else return false;
}
</pre>
<p>On the client side we need to make a request to the authentication method and copy the authentication cookie to the future requests (Here you will find an easy way to make post requests using C#):</p>
<pre class="brush: csharp;">
Cookie cookie = authenticate_response.Cookies[&quot;.ASPXAUTH&quot;];
new_request.CookieContainer = new CookieContainer();
new_request.CookieContainer.Add(cookie);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.manglar.com/fba-on-desktop-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making a JSON service request using C#</title>
		<link>http://blog.manglar.com/json-post-request/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=json-post-request</link>
		<comments>http://blog.manglar.com/json-post-request/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 21:34:20 +0000</pubDate>
		<dc:creator>Germán Medina</dc:creator>
				<category><![CDATA[Tech Recipes]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Post]]></category>
		<category><![CDATA[Webservices]]></category>

		<guid isPermaLink="false">http://manglar.wordpress.com/?p=42</guid>
		<description><![CDATA[This is an easy way to make a JSON POST request to a remote service using C#:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = &#34;POST&#34;;
request.ContentType = &#34;application/json; charset:utf-8&#34;;
DataContractJsonSerializer ser = new DataContractJsonSerializer(data.GetType());
MemoryStream ms = new MemoryStream();
ser.WriteObject(ms, data);
String json = Encoding.UTF8.GetString(ms.ToArray());
StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.Write(json);
writer.Close();

Notice that in line 4 we create an instance of DataContractJsonSerializer (Assembly: System.ServiceModel.Web) and initialize ]]></description>
			<content:encoded><![CDATA[<p>This is an easy way to make a JSON POST request to a remote service using C#:</p>
<pre class="brush: csharp;">
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = &quot;POST&quot;;
request.ContentType = &quot;application/json; charset:utf-8&quot;;
DataContractJsonSerializer ser = new DataContractJsonSerializer(data.GetType());
MemoryStream ms = new MemoryStream();
ser.WriteObject(ms, data);
String json = Encoding.UTF8.GetString(ms.ToArray());
StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.Write(json);
writer.Close();
</pre>
<p>Notice that in line 4 we create an instance of DataContractJsonSerializer (Assembly: System.ServiceModel.Web) and initialize it with the type of object we are serializing as JSON to send to the service. In lines 5 and 6 the serializer writes the object into a Stream. Line 7 transforms the Stream into an UTF-8 String (as the content-type) and finally in lines 8 to 10 we send the data to the service.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.manglar.com/json-post-request/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
