0

私の WCF サービスは、任意のサーバーで動作します。私のクライアント - コンソール アプリケーションです。コマンド ライン パラメータで、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サービスの別のアドレスを使用するにはどうすればよいですか?

4

1 に答える 1

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 抽象化を使用して、コマンドラインからプロパティ値を取得できます。参照: 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>

次のようにコマンドラインで変数を設定します: program.exe --serviceUrl=http://localhost/Service.svc

于 2011-07-06T20:36:30.203 に答える