title: Unable to generate Web Service proxy with interface compiled by wsdl.exe
body: <p>I am building a broker service that invokes several back-end services (currently 2). All the services have the same interface. The following slide, while not in English, shows the deployment</p>
  
  <p><img src="https://i.stack.imgur.com/6qh86.jpg" alt="Diagram"></p>
  
  <p>The interface was compiled from WSDL with wsdl.exe. The interface obviously contains all C# attributes</p>
  
  <pre><code>[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 {
  
      /// &lt;remarks/&gt;
      [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);
  
      /// &lt;remarks/&gt;
      [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);
  
      /// &lt;remarks/&gt;
      [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);
  }
  </code></pre>
  
  <p>The broker is built up on Spring.net with dynamic proxy and skeleton instantiation. It consists of an empty webapp that exposes a Web Service implemented in another assembly.</p>
  
  <p>The broker contains references to other services through its own interface:</p>
  
  <pre><code>class Broker : IServizioSanitario
  {
          public IServizioSanitario[] ServiziConcreti { private get; set; }
  }
  </code></pre>
  
  <p>I want to instantiate dynamic proxies for each service called by the broker. For this I have used Spring.net dependency injection Fragment:</p>
  
  <pre><code>    &lt;object id="ServizioSanitarioNetProxy" type="Spring.Web.Services.WebServiceProxyFactory, Spring.Services"&gt;
          &lt;property name="ServiceUri" value="http://localhost:2263/ServizioSanitario2.asmx"/&gt;
          &lt;property name="ServiceInterface" value="It.Unina.MasterICT.ServizioSanitarioReference.IServizioSanitario, ServizioSanitarioReference"/&gt;
        &lt;/object&gt;
  
    &lt;object id="BrokerConcrete" type="It.Unina.MasterICT.ServizioSanitario.Broker.Broker, BrokerImpl"&gt;
      &lt;property name="ServiziConcreti"&gt;
        &lt;list&gt;
          &lt;ref object="ServizioSanitarioDummyProxy"/&gt;
          &lt;ref object="ServizioSanitarioNetProxy"/&gt;
        &lt;/list&gt;
      &lt;/property&gt;
    &lt;/object&gt;
  </code></pre>
  
  <p>When I try to run the webapp I get the following error</p>
  
  <pre><code>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&amp; result, Object&amp; resultRuntimeObject) +1153
     System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object&amp; result, Object&amp; 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&amp; completedSynchronously) +184
  </code></pre>
  
  <p>Following the Spring tutorials, they use interfaces created by hand and not compiled from wsdl.exe. At <strong><a href="http://localhost:2263/ServizioSanitario2.asmx" rel="nofollow noreferrer">http://localhost:2263/ServizioSanitario2.asmx</a></strong> I have another project, from another solution, running a Web Service that is defined like this: <strong>public class ServizioSanitario2 : System.Web.Services.WebService, IServizioSanitario</strong> where <strong>IServizioSanitario</strong> again comes from wsdl.exe compilation.</p>
  
  <p>In my current assignment, it's important to clearly show the usage of interfaces (=of the same interface) to allow interchangeability of implementation classes (I'll basically show that the providers can be changed with remote or local objects at any time).</p>
  
  <p>So I would like to come past this error <strong>without</strong> having to handcaft a new interface that is basically the one shown above without attributes.</p>
  
  <p>Is it possible? Consider that I have complex data types to be exchanged in <strong>SOAP</strong> messages, so having "<strong>clear-of-attributes</strong>" interfaces isn't really feasible because data objects have their own XML Serialization attributes.</p>
  
  <p>Thank you.</p>