During my day to day work, I frequently find useful information, from various blogs spread all over the Internet. In order to avoid others repeating my same researches, I decided to share my findings in this blog, with no claiming to be exhaustive nor teaching anything to anyone. These postings are provided 'AS IS' with no warranties, and confer no rights. The views expressed on this weblog are mine alone.
giovedì 30 gennaio 2014
Community Days 2014
Organized by Italian community and user group devoted to Microsoft products and technologies, to offer study days in the form of technical conferences.
martedì 14 gennaio 2014
Calling a WCF service through a proxy server.
C# .NET
Framework 4.0
I have an
application client that calls a WCF service and in this client uses a proxy for
the internet connection, so when I call my service I must first provide the
proxy authentication.
I have
created a class that implements the IWebProxy interface:
namespace Utililty {
public class ProxyConfig : IWebProxy {
public ICredentials Credentials {
get
{
using (var context = new AOEntities())
{
var query =
from data in context.ConnectionParameters
where data.ServerName.Equals("Proxy")
select data;
if (query.Any())
{
var parameters =
query.FirstOrDefault();
if (parameters != null) return new NetworkCredential(parameters.UserName,
parameters.Password);
}
return null;
}
}
set { }
}
public Uri GetProxy(Uri destination) {
return WebRequest.GetSystemWebProxy().GetProxy(destination);
}
public bool IsBypassed(Uri host) {
return WebRequest.GetSystemWebProxy().IsBypassed(host);
}
}
}
In this example,
I retrieve the credentials from a SQL Server database, but if you prefer you
can put in the application configuration file.
Then in the
application configuration file (app.config), I have added this section:
<system.net>
<defaultProxy>
<module type=" Utililty.ProxyConfig, Utililty"/>
</defaultProxy>
</system.net>
and the attribute useDefaultWebProxy="true" at the WCF binding configuration.
The ProxyConfig
object will have call automatically before your call to service.
Peace & Love!
Iscriviti a:
Post (Atom)