내 응용 프로그램이 런타임에 끝점 설정을 변경하고 구성 파일의 변경 사항을 유지합니다. 그러나 새로운 서비스 프록시 인스턴스를 만들 때 엔드 포인트 설정은 업데이트 전이었습니다. 프록시가 강제로 새 설정을 가져 오도록하려면 어떻게합니까?WCF 서비스 프록시가 구성 파일에서 바인딩 설정을 새로 고치지 않습니다.
1
A
답변
3
기본 app.config/web.config 또는 configSource를 통해 사용중인 외부 구성 파일로 구성 파일이 업데이트되었는지 감지해야합니다.
변화가 감지 될 경우이는 system.serviceModel 구성 섹션을 새로해야합니다
ConfigurationManager.RefreshSection("system.serviceModel/client");
가 폐쇄하고 새로운 생성해야합니다 있도록 변경 사항을 적용하지 않습니다 Channels
및 ChannelFactories
기존.
다음의 예는 행동이 보여줍니다
[TestFixture]
class When_trying_to_change_service_endpoints_on_the_fly
{
[Test]
public void Should_use_the_new_endpoint()
{
var someService1 = Substitute.For<ISomeWebService>();
var someService2 = Substitute.For<ISomeWebService>();
var serviceHost1 = CreateServiceHost(someService1, new Uri("http://localhost:50001"));
var serviceHost2 = CreateServiceHost(someService2, new Uri("http://localhost:50002"));
serviceHost1.Open();
serviceHost2.Open();
UpdateEndpointInConfig(new Uri("http://localhost:50001"));
var channelFactory = new ChannelFactory<ISomeWebService>("TestReloadConfig");
var channel1 = channelFactory.CreateChannel();
channel1.ServiceMethod();
((IChannel)channel1).Close();
channelFactory.Close();
UpdateEndpointInConfig(new Uri("http://localhost:50002"));
channelFactory = new ChannelFactory<ISomeWebService>("TestReloadConfig");
var channel2 = channelFactory.CreateChannel();
channel2.ServiceMethod();
((IChannel)channel2).Close();
serviceHost1.Close();
serviceHost2.Close();
someService1.Received(1).ServiceMethod();
someService2.Received(1).ServiceMethod();
}
private static void UpdateEndpointInConfig(Uri endpointAddress)
{
var configFile = new ExeConfigurationFileMap();
configFile.ExeConfigFilename = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath;
var config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
var serviceModelConfig = (ServiceModelSectionGroup) config.GetSectionGroup("system.serviceModel");
serviceModelConfig.Client.Endpoints[0].Address = endpointAddress;
config.Save();
ConfigurationManager.RefreshSection("system.serviceModel/client");
}
private ServiceHost CreateServiceHost<TService>(TService service, Uri baseUri)
{
var serviceHost = new ServiceHost(service, new Uri[0]);
serviceHost.Description.Behaviors.Find<ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;
serviceHost.Description.Behaviors.Find<ServiceBehaviorAttribute>().InstanceContextMode = InstanceContextMode.Single;
serviceHost.AddServiceEndpoint(typeof(TService), new BasicHttpBinding(), baseUri);
return serviceHost;
}
}
[ServiceContract]
public interface ISomeWebService
{
[OperationContract]
void ServiceMethod();
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<client>
<endpoint address="http://localhost:50000" binding="basicHttpBinding" contract="Junk.ISomeWebService" name="TestReloadConfig" />
</client>
</system.serviceModel>
</configuration>
엔드 포인트 구성 당신이 엔드 포인트와 바인딩 속성에 액세스 할 수 당신이 수동으로 ChannelFactory
인스턴스를 업데이트 할 수있는 다른 방법을 관리합니다.
관련 문제
- 1. 구성 바인딩 검색 WCF
- 2. WCF 서비스 바인딩 - 시간 초과 구성
- 3. WCF 웹 서비스 내의 구성 파일에서 읽기
- 4. WCF 바인딩 설정은 WCF 셀프 호스팅 서비스 엔드 포인트의 구성 설정을 변경하는
- 5. WCF 서비스 구성 파일?
- 6. Django가 staticfiles를 새로 고치지 않습니다
- 7. WCF REST 질문, 바인딩, 구성
- 8. 서비스 측면의 WCF 바인딩
- 9. WCF 서비스 바인딩 설정
- 10. WCF 서비스 바인딩
- 11. WCF 서비스 및 BizTalk 서비스 구성 오류
- 12. wcf 서비스 참조 구성
- 13. sqldependancy에서 캐시를 새로 고치지 않습니다.
- 14. 클릭하여 tabledata를 새로 고치지 않습니다
- 15. Mustache.js 캐시를 새로 고치지 않습니다.
- 16. 레일스가 코드를 새로 고치지 않습니다.
- 17. 브라우저가 html을 새로 고치지 않습니다
- 18. LINQ가 데이터를 새로 고치지 않습니다.
- 19. Admob이 광고를 새로 고치지 않습니다
- 20. UpdatePanel이 화면을 새로 고치지 않습니다.
- 21. DataGridView는 단순히 새로 고치지 않습니다
- 22. ListBox가 ObservableCollection을 새로 고치지 않습니다.
- 23. jquery 템플릿이 데이터를 새로 고치지 않습니다.
- 24. WCF - 사용자 지정 바인딩 구성
- 25. VS2010의 WCF 서비스 구성
- 26. WCF 데이터 서비스 구성
- 27. Silverlight 목록 상자가 목록을 새로 고치지 않습니다.
- 28. 다트 웹 구성 요소가 UI 목록을 새로 고치지 않습니다.
- 29. WCF 클라이언트가 다른 설정 파일에서 설정을 읽도록하는 방법은 무엇입니까?
- 30. WCF 사용자 지정 바인딩 - 서비스