无法公开多个服务 - Spring WebServiceExporter

时间:2016-03-20 00:55:12

标签: asp.net web-services spring.net

嗨,我对Spring来说还是比较新的。我一直在使用WebServiceExporter来公开我的WebServices。但是,当我尝试将另一个WebService添加到我的Web.xml时,我收到以下错误:

[ArgumentException: Duplicate type name within an assembly.]
System.Reflection.Emit.ModuleBuilder.CheckTypeNameConflict(String strTypeName, Type enclosingType) +14200621
System.Reflection.Emit.AssemblyBuilderData.CheckTypeNameConflict(String strTypeName, TypeBuilder enclosingType) +91
System.Reflection.Emit.TypeBuilder.Init(String fullname, TypeAttributes attr, Type parent, Type[] interfaces, ModuleBuilder module, PackingSize iPackingSize, Int32 iTypeSize, TypeBuilder enclosingType) +161
System.Reflection.Emit.ModuleBuilder.DefineTypeNoLock(String name, TypeAttributes attr, Type parent, Type[] interfaces, PackingSize packingSize, Int32 typesize) +103
System.Reflection.Emit.ModuleBuilder.DefineType(String name, TypeAttributes attr, Type parent) +289
Spring.Proxy.DynamicProxyManager.CreateTypeBuilder(String typeName, Type baseType) +145

[ArgumentException: Proxy already registered for "UserWebService" as Type "UserWebService".]
Spring.Proxy.DynamicProxyManager.CreateTypeBuilder(String typeName, Type baseType) +353
Spring.Proxy.CompositionProxyTypeBuilder.BuildProxyType() +149
Spring.Web.Services.WebServiceExporter.GenerateProxy() +333
Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InvokeInitMethods(Object target, String name, IConfigurableObjectDefinition definition) +269
Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) +660
Spring.Objects.Factory.Support.WebObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) +135
Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure) +933

[ObjectCreationException: Error creating object with name 'UserWebService' defined in 'file [C:\CODE\Kupla\Kupla\Web.xml] line 13' : Initialization of object failed : Proxy already registered for "UserWebService" as Type "UserWebService".]
Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure) +1419
Spring.Objects.Factory.Support.AbstractObjectFactory.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) +389
Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectInternal(String name, Type requiredType, Object[] arguments, Boolean suppressConfigure) +2103
Spring.Objects.Factory.Support.DefaultListableObjectFactory.PreInstantiateSingletons() +875
Spring.Context.Support.AbstractApplicationContext.Refresh() +1225
Spring.Context.Support.WebApplicationContext..ctor(WebApplicationContextArgs args) +179
_dynamic_Spring.Context.Support.WebApplicationContext..ctor(Object[] ) +252
Spring.Context.Support.RootContextInstantiator.InvokeContextConstructor(ConstructorInfo ctor) +168
Spring.Context.Support.ContextHandler.InstantiateContext(IApplicationContext parentContext, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources) +192
Spring.Context.Support.WebContextHandler.InstantiateContext(IApplicationContext parent, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources) +413
Spring.Context.Support.ContextHandler.Create(Object parent, Object configContext, XmlNode section) +520

[ConfigurationErrorsException: Error creating context 'spring.root': Duplicate type name within an assembly.]
System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) +347
System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) +2277
System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) +1849
System.Configuration.BaseConfigurationRecord.GetSection(String configKey) +69
Spring.Util.ConfigurationUtils.GetSection(String sectionName) +270
Spring.Context.Support.WebApplicationContext.GetContextInternal(String virtualPath) +1663
Spring.Context.Support.WebSupportModule.Init(HttpApplication app) +665
System.Web.HttpApplication.InitModulesCommon() +192
System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers) +1678
System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context) +390
System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +194
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +293

有没有其他人在春天遇到过这种情况,我真的很想知道出了什么问题。我的web.xml包含:

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">

<object type="default.aspx">
<property name="SessionObjectHolder" ref="SessionObjectHolder"/>
</object>

<object type="home.aspx">
<property name="UserBLL" ref="UserBLL"/>
<property name="SessionObjectHolder" ref="SessionObjectHolder"/>
</object>

<object id="UserWebService" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName" value="UserWebServiceDTO"/>
<property name="Namespace" value="http://test.co.uk"/>
<property name="Description" value="This is User Web Service"/>
<property name="TypeAttributes">
  <list>
    <object type="System.Web.Script.Services.ScriptServiceAttribute, System.Web.Extensions"/>
  </list>
</property>
</object>

<object id="UserWebServiceDTO" type="Kupla.ServiceLayer.UserWebService, Kupla.ServiceLayer">
<property name="UserBLL" ref="UserBLL" />
</object>

<object id="SessionObjectHolderWebService" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName" value="SessionObjectHolderWebServiceDTO"/>
<property name="Namespace" value="http://test.co.uk"/>
<property name="Description" value="This is the session object holder web service"/>
<property name="TypeAttributes">
  <list>
    <object type="System.Web.Script.Services.ScriptServiceAttribute, System.Web.Extensions"/>
  </list>
</property>
</object>

<object id="SessionObjectHolderWebServiceDTO" type="Kupla.ServiceLayer.SessionObjectHolderWebService, Kupla.ServiceLayer">
<property name="UserBLL" ref="UserBLL" />
</object>
</objects>

许多人提前感谢。

1 个答案:

答案 0 :(得分:1)

您的asmxsvc文件是否存在?在Spring创建服务时应该删除它们,因为一个实例是由Spring创建的,第二个是由IIS / .NET创建的。

修改

我之前没有找到,但WebServiceExporter会在您的案例中注册对象名称的类型 - UserWebServiceSessionObjectHolderWebService。但是这些类型已经存在(由您自己创建),您可以使用DTO后缀调用这些对象。尝试将后缀Exporter添加到WebServiceExporter创建的对象中。

在配置文件中交换服务时出现不同错误的原因是Spring只返回第一个错误。在大型项目中可能会非常痛苦。