我正在silverlight中创建一个应用程序。该应用程序的XAP文件夹包含ServiceReferencesClientConfig文件。我已经将该应用程序部署在网络服务器上,每当我从其他机器访问该网站时(http://192.168.1.15/SampleApplication/Login.aspx)
,我想将该IP地址(192.168.1.15)写入ServiceReferencesClientConfig 之后应该将 Xap 文件下载到客户端。但我不知道以编程方式编辑 ServiceReferencesClientConfig 文件。(我想在更改部署应用程序的网络服务器的 IP 地址时进行更改,它应该自动更改 ServiceReferencesClientConfig,因此无需手动更改 ServiceReferencesClientConfig 文件。)
问问题
871 次
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 回答