Azure AD at Techorama 2016
Fa 10 anys
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TransparentProxy
{
interface IProxy<T>
T Client {get;}
void Close();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TransparentProxy
{
public class Proxy<T>: IProxy<T>
{
public T Client
{
get { throw new NotImplementedException(); }
}
public void Close()
{
throw new NotImplementedException();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Channels;
namespace TransparentProxy
{
public class Proxy<T>: IProxy<T>
{
ChannelFactory<T> ch;
public Proxy(Binding bind, string addr , string userName, string password )
{
ch = new ChannelFactory<T>(bind, new EndpointAddress(addr));
if ((userName != null) && (password!=null))
{
// És un exemple, les credencials poden ser passades
// d'altres maneres, certificats, tokens, etc.
// Cal docuementar-se.
ch.Credentials.UserName.UserName = userName;
ch.Credentials.UserName.Password = password;
}
}
public T Client
{
get { return ch.CreateChannel(); }
}
public void Close()
{
ch.Close();
}
}
}
WSHttpBinding bind=new WSHttpBinding(); bind.Security.Mode = SecurityMode.Message; bind.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; bind.Security.Message.ClientCredentialType = MessageCredentialType.Windows; bind.Security.Message.NegotiateServiceCredential = true; TransparentProxy.IProxyproxy = new TransparentProxy.Proxy (bind, "http://localhost:53538/WCFGAPService/Service.svc", null, null); IList res = proxy.Client.LListarMetges(); proxy.Close(); return res;