2011-07-06 13 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サービスの別のアドレスを使用できますか?あなたはコマンドラインからプロパティ値を取得するためにIVariableSource抽象化を使用することができます

<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> 

答えて

1

はそのような何かを試してみてください。参照: 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> 

は、このようなコマンドラインで変数を設定

関連する問題