PDA

View Full Version : Error at first call of WebServiceExporter.GenerateProxy()


Cristiano Simionato
12-18-2007, 03:27 PM
After updating Spring.Net from 1.1 M1 to 1.1 Final Release, the first time the web service (.asmx page) is called, after an iisreset, IIS return a "Duplicate type name within an assembly" exception: the web service is correctly started, and a refresh of the browser show correctly the web method list.

Exception:
[ArgumentException: Nome tipo duplicato in un assembly.]
System.Reflection.Emit.AssemblyBuilderData.CheckTy peNameConflict(String strTypeName, TypeBuilder enclosingType) +2654633
System.Reflection.Emit.TypeBuilder.Init(String fullname, TypeAttributes attr, Type parent, Type[] interfaces, Module module, PackingSize iPackingSize, Int32 iTypeSize, TypeBuilder enclosingType) +171
System.Reflection.Emit.ModuleBuilder.DefineTypeNoL ock(String name, TypeAttributes attr, Type parent) +97
System.Reflection.Emit.ModuleBuilder.DefineType(St ring name, TypeAttributes attr, Type parent) +102
Spring.Proxy.DynamicProxyManager.CreateTypeBuilder (String typeName, Type baseType) +61
Spring.Web.Services.WebServiceProxyTypeBuilder.Cre ateTypeBuilder(String name, Type baseType) +11
Spring.Proxy.CompositionProxyTypeBuilder.BuildProx yType() +72
Spring.Web.Services.WebServiceExporter.GeneratePro xy() +226
Spring.Web.Services.WebServiceExporter.AfterProper tiesSet() +72
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.InvokeInitMethods(Object target, String name, IConfigurableObjectDefinition definition) +177
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) +512
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching) +581

[ObjectCreationException: Error creating object with name 'DocumentHistoryExporter' defined in 'file [D:\OrangeSource\DocumentHistory\DocumentHistory.Se rvices\Webservices.config]' : Initialization of object failed : Nome tipo duplicato in un assembly.]
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching) +732
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments) +17
Spring.Objects.Factory.Support.AbstractObjectFacto ry.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) +157
Spring.Objects.Factory.Support.WebObjectFactory.Cr eateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) +89
Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name, Type requiredType, Object[] arguments) +475
Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name) +32
Spring.Objects.Factory.Support.DefaultListableObje ctFactory.PreInstantiateSingletons() +468
Spring.Context.Support.AbstractApplicationContext. Refresh() +529
Spring.Context.Support.WebApplicationContext..ctor (String name, Boolean caseSensitive, IApplicationContext parentContext, String[] configurationLocations) +54
Spring.Context.Support.WebApplicationContext..ctor (String name, Boolean caseSensitive, String[] configurationLocations) +17

[TargetInvocationException: Eccezione generata dalla destinazione di una chiamata.]
System.RuntimeMethodHandle._InvokeConstructor(Obje ct[] args, SignatureStruct& signature, IntPtr declaringType) +0
System.RuntimeMethodHandle.InvokeConstructor(Objec t[] args, SignatureStruct signature, RuntimeTypeHandle declaringType) +13
System.Reflection.RuntimeConstructorInfo.Invoke(Bi ndingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +366
Spring.Util.ObjectUtils.InstantiateType(Constructo rInfo constructor, Object[] arguments) +157

[FatalReflectionException: Cannot instantiate Type [Spring.Context.Support.WebApplicationContext] using ctor [Void .ctor(System.String, Boolean, System.String[])] : 'Eccezione generata dalla destinazione di una chiamata.']
Spring.Util.ObjectUtils.InstantiateType(Constructo rInfo constructor, Object[] arguments) +324
Spring.Context.Support.RootContextInstantiator.Inv okeContextConstructor(ConstructorInfo ctor) +99
Spring.Context.Support.ContextInstantiator.Instant iateContext() +31
Spring.Context.Support.ContextHandler.InstantiateC ontext(IApplicationContext parentContext, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources) +137
Spring.Context.Support.WebContextHandler.Instantia teContext(IApplicationContext parent, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources) +305
Spring.Context.Support.ContextHandler.Create(Objec t parent, Object configContext, XmlNode section) +284

[ConfigurationErrorsException: Error creating context '/documenthistory.services': Nome tipo duplicato in un assembly.]
System.Configuration.BaseConfigurationRecord.Evalu ateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) +178
System.Configuration.BaseConfigurationRecord.Evalu ate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) +896
System.Configuration.BaseConfigurationRecord.GetSe ctionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) +1221
System.Configuration.BaseConfigurationRecord.GetSe ction(String configKey, Boolean getLkg, Boolean checkPermission) +56
System.Configuration.BaseConfigurationRecord.GetSe ction(String configKey) +8
System.Web.Configuration.HttpConfigurationSystem.S ystem.Configuration.Internal.IInternalConfigSystem .GetSection(String configKey) +65
System.Configuration.ConfigurationManager.GetSecti on(String sectionName) +107
Spring.Util.ConfigurationUtils.GetSection(String sectionName) +4
Spring.Context.Support.WebApplicationContext.GetCo ntextInternal(String virtualPath) +1088
Spring.Context.Support.WebApplicationContext.GetRo otContext() +75
Spring.Context.Support.WebSupportModule.Init(HttpA pplication app) +321
System.Web.HttpApplication.InitModulesCommon() +66
System.Web.HttpApplication.InitInternal(HttpContex t context, HttpApplicationState state, MethodInfo[] handlers) +814
System.Web.HttpApplicationFactory.GetNormalApplica tionInstance(HttpContext context) +243
System.Web.HttpApplicationFactory.GetApplicationIn stance(HttpContext context) +106
System.Web.HttpRuntime.ProcessRequestInternal(Http WorkerRequest wr) +340


Web.config:
<configuration>
<configSections>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="~/Webservices.config"/>
</context>
</spring>
<connectionStrings/>
<system.web>
<compilation debug="true">
<assemblies>
<add assembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>
</compilation>
<authentication mode="Windows"/>
<!--<httpHandlers>
<add verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web"/>
</httpHandlers>-->
<httpModules>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</httpModules>
<webServices>
<conformanceWarnings>
<remove name="BasicProfile1_1"/>
</conformanceWarnings>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
<httpRuntime maxRequestLength="524288"/>
</system.web>
<!-- NHibernate and Log4Net section [...] -->
</configuration>


webservice.config:
<object name="MyWebServices.asmx" type="MyNameSpace.WsMyWebServices, MyNameSpace" abstract="true"/>
<object id="WsMyWebServices" type="MyNameSpace.WsMyWebServices, MyNameSpace"/>
<object id="MyWebServicesExporter" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="Namespace" value="http://www.myCompany.it/MyWebServices"/>
<property name="TargetName" value="WsMyWebServices"/>
</object>


Someone could help me, please?

Bruno Baia
12-19-2007, 11:02 AM
Hi,

I don't understand this :

<object name="MyWebServices.asmx" type="MyNameSpace.WsMyWebServices, MyNameSpace" abstract="true"/>


You web service will be available at <WebServiceExporter's object id>.asmx which means in your case : MyWebServicesExporter.asmx


If your class "MyNameSpace.WsMyWebServices, MyNameSpace" already contains the WebService attributes, it will also be available at "WsMyWebServices.asmx".


I will investigate the IIS reset thing and reply later.


There's a related improvement about this in JIRA for 1.1.1 :
http://opensource.atlassian.com/projects/spring/browse/SPRNET-762

- Bruno

Cristiano Simionato
12-19-2007, 01:40 PM
I don't understand this :

<object name="MyWebServices.asmx" type="MyNameSpace.WsMyWebServices, MyNameSpace" abstract="true"/>



I have readed about it in the documentation: chapter "27.2.1. Removing the need for .asmx files" point "2. Create an object definition for one's web service."

What I don't have understood? :confused:

However, I have followed your instruction but the problem remain.

I will investigate the IIS reset thing and reply later.


I have forgotten to say the I use the IIS 5 distributed with WinXP Pro SP2.

Thanks a lot for your time.

Cristiano

Bruno Baia
12-20-2007, 11:10 PM
Hi,

I have readed about it in the documentation: chapter "27.2.1. Removing the need for .asmx files" point "2. Create an object definition for one's web service."

What I don't have understood? :confused:

Sorry, there was an error in the documentation :

You should read :

<object name="HelloWorld" type="MyComany.MyApp.Services.HelloWorldService, MyAssembly" abstract="true"/>

instead of :

<object name="HelloWorld.asmx" type="MyComany.MyApp.Services.HelloWorldService, MyAssembly" abstract="true"/>

And your service should be available at HelloWorld.asmx



If your service class already contains all the necessary web attributes, you don't need to use the WebServiceExporter, so your configuration file should looks like this :

<object name="MyWebServices" type="MyNameSpace.WsMyWebServices, MyNameSpace" abstract="true"/>

And the web service will be available at MyWebServices.asmx
Related documentation reference :
27.2.1. Removing the need for .asmx files (http://www.springframework.net/docs/1.1/reference/html/webservices.html#d0e15194)


If your class does not have the web attributes applied or you want to do some DI/AOP, you have to use the WebServiceExporter :

<object id="MyServices" type="MyNameSpace.MyServices, MyAssembly"/>
<object id="MyWebServices" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="Namespace" value="http://www.myCompany.it/MyWebServices"/>
<property name="TargetName" value="MyServices"/>
</object>

And the web service will be available at MyWebServices.asmx
Related documentation reference :
27.2.2. Injecting dependencies into web services (http://www.springframework.net/docs/1.1/reference/html/webservices.html#server-side)
27.2.3. Exposing PONOs as Web Services
27.2.4. Exporting an AOP Proxy as a Web Service


I could not reproduce your error with iisreset, and I got the same configuration.
How did you generate your binaries ?
Web Site, Web application project, Web deployement project ?


- Bruno

Cristiano Simionato
01-08-2008, 04:24 PM
Hi,

I could not reproduce your error with iisreset, and I got the same configuration.
How did you generate your binaries ?
Web Site, Web application project, Web deployement project ?


- Bruno

The class MyNameSpace.WsMyWebServices already contains all the necessary web attributes, so using only

<object name="MyWebServices" type="MyNameSpace.WsMyWebServices, MyNameSpace" abstract="true"/>


the exception at the first call of WS doesn't appear; maybe if I also declare the WebServiceExporter there is a problem with the web attributes inside the class.

I generate the binaries with VS2005, Web Site.

Thanks a lot for your help :)

Cristiano

Bruno Baia
01-10-2008, 01:24 PM
Hi,

WebServiceExporter is only needed if you nedd to apply DI/AOP to your service or if you want expose a PONO object (not decorated with web services specific attributes) as a Web Service.
So you don't need it here.

- Bruno