私は Silverlight でアプリケーションを作成しています。そのアプリケーションの XAP フォルダーには ServiceReferencesClientConfig ファイルが含まれています。そのアプリケーションを Web サーバーにデプロイし(http://192.168.1.15/SampleApplication/Login.aspx)
ました。 ServiceReferencesClientConfig に続いて、Xap ファイルをクライアント側にダウンロードする必要があります。しかし、プログラムで ServiceReferencesClientConfig ファイルを編集するという考えはありません。(アプリケーションがデプロイされている Web サーバーの IP アドレスを変更するときに、その変更を行いたいと思います。ServiceReferencesClientConfig ファイルを手動で変更する必要がないように、ServiceReferencesClientConfig を自動的に変更する必要があります。)
1 に答える
1
オプションとして、動的に生成されたエンドポイントとバインディングを使用するように既定のコンストラクターを変更するか、ファクトリを使用して同じことを行うことで、サービス プロキシを動的に構成できます。
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;
}
}
于 2013-01-23T13:28:43.833 に答える