2011-07-06 2 views
0

내 WCF 서비스는 모든 서버에서 작동 할 수 있습니다. 내 클라이언트 - 콘솔 응용 프로그램입니다. 명령 줄 매개 변수에서 내 WCF 서비스의 주소를 설정해야합니다. 설정 클라이언트에서 현재 내가 가지고spring.net을 사용할 때 클라이언트의 명령 줄에서 WCF 서비스 주소를 설정할 수있는 방법

... 
<spring> 
    <context> 
     <resource uri="assembly://MyAssembly.Console/MyAssembly.Console/ServerWeb.xml"/> 
    </context> 
    </spring> 
... 
<system.serviceModel> 
<client> 
     <endpoint behaviorConfiguration="Default" name="serverWebDataServiceEndpoint" address="http://localhost/mydata/DataService.svc" 
       binding="basicHttpBinding" bindingConfiguration="basicHttpBinding1" contract="MyData.Contracts.IDataService"/> 
    </client> 
... 

파일 ServerWeb.xml은 다음과 같습니다

응용 프로그램에서
<?xml version="1.0" encoding="utf-8" ?> 
<objects xmlns="http://www.springframework.net" 
     xmlns:wcf="http://www.springframework.net/wcf"> 

    <wcf:channelFactory id="serverWebDataService" 
    channelType="VimpelCom.Fmrad.Theseus.WcfDataLayer.CommonTypes.Contracts.IDataService, VimpelCom.Fmrad.Theseus.WcfDataLayer.CommonTypes" 
    endpointConfigurationName="serverWebDataServiceEndpoint" /> 

</objects> 

, 내가 전화 서비스의 메서드를 들어, 다음 코드를 사용

IApplicationContext _ctx = ContextRegistry.GetContext(); 
IDataService _dataService = _ctx["serverWebDataService"] as IDataService; 

var rule = _dataService.GetRuleById(ruleId); 

어떻게 명령 줄에서 WCF 서비스의 다른 주소를 사용할 수 있습니까? 그런

답변

1

시도 뭔가 :

<wcf:channelFactory id="serverWebDataService" 
    channelType="VimpelCom.Fmrad.Theseus.WcfDataLayer.CommonTypes.Contracts.IDataService, VimpelCom.Fmrad.Theseus.WcfDataLayer.CommonTypes" 
    endpointConfigurationName="serverWebDataServiceEndpoint"> 
    <!-- You can use classic DI to configure the ChannelFactory<T> instance --> 
    <wcf:property name="Endpoint.Address"> 
    <object type="System.ServiceModel.EndpointAddress, System.ServiceModel"> 
     <constructor-arg name="uri" value"${serviceUrl}"/> 
    </object> 
    </wcf:property> 
</wcf:channelFactory> 

당신은 명령 줄에서 속성 값을 얻을 수 IVariableSource 추상화를 사용할 수 있습니다. 참조 : 은 Program.exe --serviceUrl = HTTP : //localhost/Service.svc

http://www.springframework.net/doc-latest/reference/html/objects.html#objects-variablesource

<object type="Spring.Objects.Factory.Config.VariablePlaceholderConfigurer, Spring.Core"> 
    <property name="VariableSources"> 
     <list> 
     <object type="Spring.Objects.Factory.Config.CommandLineArgsVariableSource, Spring.Core"> 
      <property name="ArgumentPrefix" value="--" /> 
      <property name="ValueSeparator" value="="/> 
     </object> 
     </list> 
    </property> 
</object> 

는 다음과 같이 명령 행에서 변수를 설정