我有一个将 Spring.NET 用于 IOC 的应用程序,以及它提供的许多其他功能。我现在要解决的问题是如何设置类似于 WebServiceProxyFactory 的东西来自动代理我想在应用程序中使用的 Web 服务。此配置非常适用于单个服务端点。
<object id="MyServiceClient" type="Spring.Web.Services.WebServiceProxyFactory, Spring.Services">
<property name="ServiceUri" value="https://my.service1.net/service.asmx"/>
<property name="ServiceInterface" value="Sample.IServiceClient1"/>
<property name="WebServiceProxyBaseType" value="Sample.SecureWebServiceProxy, Sample"/>
<property name="MemberAttributes">
<dictionary>
<entry key="*">
<list>
<object type="System.Web.Services.Protocols.SoapHeaderAttribute, System.Web.Services">
<constructor-arg value="ServiceAuthenticationHeader" />
<property name="Direction" value="In" />
</object>
<object type="System.Web.Services.Protocols.SoapHeaderAttribute, System.Web.Services">
<constructor-arg value="ServiceErrorStatus" />
<property name="Direction" value="Out" />
</object>
</list>
</entry>
</dictionary>
</property>
<property name="ProductTemplate">
<object>
<property name="ServiceAuthenticationHeader" ref="ServiceAuthenticationHeader" />
<property name="ServiceErrorStatus" ref="ServiceErrorStatus" />
</object>
</property>
但是,现在我需要根据应用程序中的配置设置来处理可能无限数量的端点。配置将告诉我有关服务端点的数量和详细信息,这些端点可以托管在各种 URL 上,但实现相同的接口。
我想不通的是如何配置 Spring.NET 以允许我交换ServiceUri以便它可以针对工厂生成的每个对象进行更改。我会调用 Factory 的 GetObject 方法,但想以某种方式指定它应该在生成代理对象之前使用哪个ServiceUri 。
现在我认为只实现一个自定义的 IFactoryObject 来完成幕后的艰苦工作是最好的方法。
谢谢