Reputation: 1
My WCF service can work on any servers. My client - is console application. In command line parameters I want set address of my WCF service. Current in config client I have:
...
<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>
...
File ServerWeb.xml is:
<?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>
In application, I use next code, for call service's methods:
IApplicationContext _ctx = ContextRegistry.GetContext();
IDataService _dataService = _ctx["serverWebDataService"] as IDataService;
var rule = _dataService.GetRuleById(ruleId);
How I can use another address of WCF service from command line?
Upvotes: 0
Views: 744
Reputation: 1183
Try something like that :
<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>
You can use IVariableSource abstraction to get a property value from commandline. See : 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>
Set the variable in command line like this : program.exe --serviceUrl=http://localhost/Service.svc
Upvotes: 1