3

我正在构建一个调用多个后端服务(当前为 2 个)的代理服务。所有服务都具有相同的接口。下面的幻灯片虽然不是英文的,但显示了部署

图表

该接口是使用 wsdl.exe 从 WSDL 编译的。该接口显然包含所有 C# 属性

[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.Web.Services.WebServiceBindingAttribute(Name="ServizioSanitario", Namespace="http://innovazione-ict.unina.it/WSDLSanita")]
public interface IServizioSanitario {

    /// <remarks/>
    [System.Web.Services.WebMethodAttribute()]
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://innovazione-ict.unina.it/WSDLSanita/InserisciDocumento", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
    [return: XmlElement("idDocumento", Namespace="http://innovazione-ict.unina.it/WSDLSanita", DataType="ID")]
    string InserisciDocumento([XmlElement(Namespace="http://innovazione-ict.unina.it/WSDLSanita")] Documento documento);

    /// <remarks/>
    [System.Web.Services.WebMethodAttribute()]
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://innovazione-ict.unina.it/WSDLSanita/OttieniListaDocumenti", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
    [return: XmlArray("listaMetadati", Namespace="http://innovazione-ict.unina.it/WSDLSanita")]
    [return: XmlArrayItem("metadatiDocumento", IsNullable=false)]
    MetadatiDocumentoTrovato[] OttieniListaDocumenti([XmlElement(Namespace="http://innovazione-ict.unina.it/WSDLSanita")] string codiceFiscale);

    /// <remarks/>
    [System.Web.Services.WebMethodAttribute()]
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://innovazione-ict.unina.it/WSDLSanita/RecuperaDocumento", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
    [return: XmlElement("documento", Namespace="http://innovazione-ict.unina.it/WSDLSanita")]
    Documento RecuperaDocumento([XmlElement(Namespace="http://innovazione-ict.unina.it/WSDLSanita", DataType="ID")] string idDocumento);
}

代理建立在 Spring.net 上,具有动态代理和骨架实例化。它由一个空的 webapp 组成,它公开了在另一个程序集中实现的 Web 服务。

代理通过自己的接口包含对其他服务的引用:

class Broker : IServizioSanitario
{
        public IServizioSanitario[] ServiziConcreti { private get; set; }
}

我想为代理调用的每个服务实例化动态代理。为此,我使用了 Spring.net 依赖注入片段:

    <object id="ServizioSanitarioNetProxy" type="Spring.Web.Services.WebServiceProxyFactory, Spring.Services">
        <property name="ServiceUri" value="http://localhost:2263/ServizioSanitario2.asmx"/>
        <property name="ServiceInterface" value="It.Unina.MasterICT.ServizioSanitarioReference.IServizioSanitario, ServizioSanitarioReference"/>
      </object>

  <object id="BrokerConcrete" type="It.Unina.MasterICT.ServizioSanitario.Broker.Broker, BrokerImpl">
    <property name="ServiziConcreti">
      <list>
        <ref object="ServizioSanitarioDummyProxy"/>
        <ref object="ServizioSanitarioNetProxy"/>
      </list>
    </property>
  </object>

当我尝试运行 webapp 时,出现以下错误

System.InvalidOperationException: Element idDocument, belonging to namespace http://innovazione-ict.unina.it/WSDLSanita, imported in two different contexts: PrimitiveMapping, MembersMapping.

[InvalidOperationException: Elemento idDocumento, appartenente allo spazio dei nomi http://innovazione-ict.unina.it/WSDLSanita, importato in due diversi contesti: PrimitiveMapping, MembersMapping.]
   System.Xml.Serialization.XmlSchemaImporter.ImportElementType(XmlSchemaElement element, String identifier, Type desiredMappingType, Type baseType, String ns) +813951
   System.Xml.Serialization.XmlSchemaImporter.ImportElement(XmlSchemaElement element, String identifier, Type desiredMappingType, Type baseType, String ns, Boolean topLevelElement) +284
   System.Xml.Serialization.XmlSchemaImporter.ImportElement(XmlQualifiedName name, Type desiredMappingType, Type baseType) +207
   System.Xml.Serialization.XmlSchemaImporter.ImportMembersMapping(XmlQualifiedName name) +82
   Spring.Web.Services.SoapHttpClientProxyTypeBuilder.GetMembersMapping(String messageName, MessagePartCollection messageParts, SoapBodyBinding soapBodyBinding, SoapBindingStyle soapBindingStyle) +376
   Spring.Web.Services.SoapHttpClientProxyTypeBuilder.MoveToMethod(MethodInfo targetMethod) +1481
   Spring.Web.Services.SoapHttpClientProxyTypeBuilder.ApplyMethodAttributes(MethodBuilder methodBuilder, MethodInfo targetMethod) +37
   Spring.Proxy.AbstractProxyTypeBuilder.ImplementInterface(TypeBuilder typeBuilder, IProxyMethodBuilder proxyMethodBuilder, Type intf, Type targetType, Boolean proxyVirtualMethods) +423
   Spring.Proxy.AbstractProxyTypeBuilder.ImplementInterface(TypeBuilder typeBuilder, IProxyMethodBuilder proxyMethodBuilder, Type intf, Type targetType) +50
   Spring.Web.Services.SoapHttpClientProxyTypeBuilder.BuildProxyType() +367
   Spring.Web.Services.WebServiceProxyFactory.GenerateProxy() +379
   Spring.Web.Services.WebServiceProxyFactory.GetObject() +55
   Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectFromFactoryObject(IFactoryObject factory, String objectName, RootObjectDefinition rod) +84

[ObjectCreationException: Error thrown by a dependency of object 'BrokerConcrete' defined in 'config [C:\Users\DJ Echelon\documents\visual studio 2010\Projects\MasterICT\BrokenSanitario\WebappBroker\web.config#spring/objects] line 1' : FactoryObject threw exception on object creation.
 while resolving 'ServiziConcreti[0]' to 'ServizioSanitarioNetProxy' defined in 'config [C:\Users\DJ Echelon\documents\visual studio 2010\Projects\MasterICT\BrokenSanitario\WebappBroker\web.config#spring/objects] line 1']
   Spring.Objects.Factory.Support.ObjectDefinitionValueResolver.ResolveReference(IObjectDefinition definition, String name, String argumentName, RuntimeObjectReference reference) +644
   Spring.Objects.Factory.Support.ObjectDefinitionValueResolver.ResolvePropertyValue(String name, IObjectDefinition definition, String argumentName, Object argumentValue) +672
   Spring.Objects.Factory.Support.ObjectDefinitionValueResolver.ResolveValueIfNecessary(String name, IObjectDefinition definition, String argumentName, Object argumentValue) +56
   Spring.Objects.Factory.Config.ManagedList.Resolve(String objectName, IObjectDefinition definition, String propertyName, ManagedCollectionElementResolver resolver) +599
   Spring.Objects.Factory.Support.ObjectDefinitionValueResolver.ResolvePropertyValue(String name, IObjectDefinition definition, String argumentName, Object argumentValue) +1478
   Spring.Objects.Factory.Support.ObjectDefinitionValueResolver.ResolveValueIfNecessary(String name, IObjectDefinition definition, String argumentName, Object argumentValue) +56
   Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.ApplyPropertyValues(String name, RootObjectDefinition definition, IObjectWrapper wrapper, IPropertyValues properties) +299
   Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.PopulateObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) +1218
   Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) +146
   Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure) +970
   Spring.Objects.Factory.Support.AbstractObjectFactory.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) +228
   Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectInternal(String name, Type requiredType, Object[] arguments, Boolean suppressConfigure) +1563
   Spring.Objects.Factory.Support.AbstractObjectFactory.GetObject(String name) +43
   Spring.Objects.Factory.Support.DefaultListableObjectFactory.PreInstantiateSingletons() +720
   Spring.Context.Support.AbstractApplicationContext.Refresh() +1356
   Spring.Context.Support.XmlApplicationContext..ctor(XmlApplicationContextArgs args) +334
   Spring.Context.Support.XmlApplicationContext..ctor(String name, Boolean caseSensitive, String[] configurationLocations) +76
   _dynamic_Spring.Context.Support.XmlApplicationContext..ctor(Object[] ) +238
   Spring.Reflection.Dynamic.SafeConstructor.Invoke(Object[] arguments) +42
   Spring.Context.Support.RootContextInstantiator.InvokeContextConstructor(ConstructorInfo ctor) +241
   Spring.Context.Support.ContextInstantiator.InstantiateContext() +190
   Spring.Context.Support.ContextHandler.InstantiateContext(IApplicationContext parentContext, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources) +152
   Spring.Context.Support.ContextHandler.Create(Object parent, Object configContext, XmlNode section) +536

[ConfigurationErrorsException: Error creating context 'spring.root': Elemento idDocumento, appartenente allo spazio dei nomi http://innovazione-ict.unina.it/WSDLSanita, importato in due diversi contesti: PrimitiveMapping, MembersMapping.]
   System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) +199
   System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) +1153
   System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) +1468
   System.Configuration.BaseConfigurationRecord.GetSection(String configKey) +41
   System.Web.HttpContext.GetSection(String sectionName) +52
   System.Web.Configuration.HttpConfigurationSystem.GetSection(String sectionName) +57
   System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String configKey) +6
   System.Configuration.ConfigurationManager.GetSection(String sectionName) +78
   Spring.Util.ConfigurationUtils.GetSection(String sectionName) +151
   Spring.Context.Support.WebApplicationContext.GetContextInternal(String virtualPath) +1181
   Spring.Context.Support.WebApplicationContext.GetContext(String virtualPath) +31
   Spring.Web.Services.WebServiceHandlerFactory.System.Web.IHttpHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String path) +130
   System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +203
   System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +128
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

按照 Spring 教程,它们使用手工创建的接口,而不是从 wsdl.exe 编译的。在http://localhost:2263/ServizioSanitario2.asmx我有另一个项目,来自另一个解决方案,运行一个定义如下的 Web 服务:public class ServizioSanitario2 : System.Web.Services.WebService, IServizioSanitario其中IServizioSanitario再次来自 wsdl .exe 编译。

在我目前的作业中,重要的是清楚地显示接口的使用(= 相同的接口)以允许实现类的可互换性(我将基本上表明可以随时使用远程或本地对象更改提供程序)。

所以我想克服这个错误,而不必手工制作一个基本上是上面显示的没有属性的新界面。

可能吗?考虑到要在SOAP消息中交换的复杂数据类型,因此具有“清除属性”接口实际上并不可行,因为数据对象具有自己的 XML 序列化属性。

谢谢你。

4

0 回答 0