2013-01-23 3 views
0

Silverlight에서 응용 프로그램을 만들고 있습니다. 해당 응용 프로그램의 XAP 폴더에는 ServiceReferencesClientConfig 파일이 있습니다.이 응용 프로그램을 웹 서버에 배포했으며 다른 컴퓨터에서이 웹 사이트에 액세스 할 때마다 (http://192.168.1.15/SampleApplication/Login.aspx) 그 IP 주소 (192.168.1.15)를 ServiceReferencesClientConfig에 쓰고 싶으면 Xap 파일을 클라이언트 측에 다운로드해야합니다. 하지만 프로그래밍 방식으로 ServiceReferencesClientConfig 파일을 편집 할 생각은 없습니다. (응용 프로그램이 배포 된 웹 서버의 IP 주소를 변경하면 변경해야하므로 ServiceReferencesClientConfig 파일을 수동으로 변경해야하므로 ServiceReferencesClientConfig 파일을 수동으로 변경해야합니다.)서비스 참조 편집 프로그래밍 방식으로 Silverlight의 클라이언트 구성 파일

답변

1

옵션으로 다음을 수행 할 수 있습니다. 동일한 기능을 수행 할 dinamically 생성 된 엔드 포인트와 바인딩, 또는 공장을 사용하여 사용할 기본 생성자를 변경, dinamically 서비스 프록시를 구성합니다

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; 
    } 
} 
+0

감사 아서 .....! – Dany

관련 문제