As an option, you can configure your service proxies dinamically, changing the default constructor to use dinamically generated endpoints and bindings, or using a factory to do the same:
public MyService()
: base(ServiceEx.GetBasicHttpBinding(), ServiceEx.GetEndpointAddress<T>())
{
}
public static class ServiceEx
{
private static string hostBase;
public static string HostBase
{
get
{
if (hostBase == null)
{
hostBase = System.Windows.Application.Current.Host.Source.AbsoluteUri;
hostBase = hostBase.Substring(0, hostBase.IndexOf("ClientBin"));
hostBase += "Services/";
}
return hostBase;
}
}
public static EndpointAddress GetEndpointAddress<TServiceContractType>()
{
var contractType = typeof(TServiceContractType);
string serviceName = contractType.Name;
// Remove the 'I' from interface names
if (contractType.IsInterface && serviceName.FirstOrDefault() == 'I')
serviceName = serviceName.Substring(1);
serviceName += ".svc";
return new EndpointAddress(HostBase + serviceName);
}
public static Binding GetBinaryEncodedHttpBinding()
{
// Binary encoded binding
var binding = new CustomBinding(
new BinaryMessageEncodingBindingElement(),
new HttpTransportBindingElement()
{
MaxReceivedMessageSize = int.MaxValue,
MaxBufferSize = int.MaxValue
}
);
SetTimeouts(binding);
return binding;
}
public static Binding GetBasicHttpBinding()
{
var binding = new BasicHttpBinding();
binding.MaxBufferSize = int.MaxValue;
binding.MaxReceivedMessageSize = int.MaxValue;
SetTimeouts(binding);
return binding;
}
}