View Full Version : How to leverage spring.net new enhanced clientproxy factory
I am testing spring.net new enhanced ws client proxy factory without manually generated wsdl to see how to transfer custom object like Contact/Address from service layer to client layer. Do I have to do a proxy conversion ?. Usually, when I used wsdl generated ws, I have to do conversion since .net framework 1.1 wsdl only generate fields instead of property. Therefore, I have to do a manually conversion for those customized object to be able to bind in .net grid. Even though I have a utility class can auto convert them back and forth. But it lacks the ability of convert nested object. Do spring.net offer some of framework for me to streamline my process.
After tremendous help by bruno, here is the fix.
First, I have the wrong version of spring.net, I though I had the newest build, it looks like it has been override somehow.
Second, a new layer of interface was created. I don't think it is necessary. But, it did server the purpose of clarity.
Third, I have to put MessageBinding property to my ws.xml.
It was like this before:
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<object id="MyService" type="Spring.Web.Services.WebServiceClientFactory, Spring.Services">
<property name="ServiceUrl" value="http://localhost/SpringNetService/HelloWorld1Exporter.asmx" />
<property name="ServiceInterface" value="SpringNetContract.IHelloWorld, SpringNetContract" />
</object>
<object type="~/WebForm1.aspx">
<property name="HelloWorldService" ref="MyService" />
</object>
</objects>
And here is after :
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<object id="MyService" type="Spring.Web.Services.WebServiceClientFactory, Spring.Services">
<property name="ServiceUrl" value="http://localhost/SpringNetService/HelloWorld1Exporter.asmx" />
<property name="ServiceInterface" value="SpringNetContract.IHelloWorld, SpringNetContract" />
<property name="MessageBindings">
<dictionary>
<entry key="DisplayText()" value="MyHelloWorld" />
<entry key="DisplayText2()" value="MyHelloWorld2" />
</dictionary>
</property>
</object>
<object type="~/WebForm1.aspx">
<property name="HelloWorldService" ref="MyService" />
</object>
</objects>
Great help from spring.net team!!! I was amazed how fast those guy are response my post.
Bruno Baia
03-14-2006, 05:47 PM
cool :)
About the message bindings,
the problem is you changed MessageName property of the WebMethodAttribute in the web service definition :
<entry key="DisplayText">
<object type="System.Web.Services.WebMethodAttribute, System.Web.Services">
<property name="Description">
<value>My Spring-configured HelloWorld method.</value>
</property>
<property name="MessageName">
<value>MyHelloWorld</value>
</property>
</object>
</entry>
That's why in the client side, we have to use "MessageBindings" to re bind the webmethod "MyHelloWorld" to the interface method "DisplayText".
Btw, in your case i don't see the need to redefine the MessageName property :
From MSDN :
"The MessageName property can be used to alias method or property names. The most common use of the MessageName property will be to uniquely identify polymorphic methods. By default, MessageName is set to the name of the XML Web service method."
About custom objects,
Second, a new layer of interface was created. I don't think it is necessary. But, it did server the purpose of clarity.
In this layer, you can define ur custom objects that will be referenced by your interface contract.
This is a Code-First approach.
You can read more about this in these topics :
http://forum.springframework.net/viewtopic.php?t=318
http://forum.springframework.net/viewtopic.php?t=339
http://forum.springframework.net/viewtopic.php?t=292
-Bruno
Ok, now I have a new problem.
What am i trying to do here is create a business object as the container to transfer business object from service layer to client layer.
I can't get even my service layer to work.
Here is my settings.
I have 3 projects: SpringNetService(service layer), SpringNetContract(Interface layer + business object definition), and SpringWebClient.
On interface layer, i created a class:
namespace SpringNetContract
{
/// <summary>
/// Summary description for IContact.
/// </summary>
public interface IGetContact
{
myObject GetContactbyRowId(string rowId);
}
public class myObject
{
string id=string.Empty;
string name=string.Empty;
public string Id
{
set{id=value;}
get {return id;}
}
public string Name
{
set{name=value;}
get {return name;}
}
}
}
Now, the springNetService has a reference to springNetContract.
Here is Contact.cs file in SprintNetService
namespace SpringNetService
{
/// <summary>
/// Summary description for Contact.
/// </summary>
public class getContact: SpringNetContract.IGetContact
{
public SpringNetContract.myObject GetContactbyRowId(string rowId)
{
return populatemyObject();
}
private SpringNetContract.myObject populatemyObject()
{
SpringNetContract.myObject obj=new SpringNetContract.myObject();
obj.Id="1";
obj.Name="myname";
return obj;
}
}
}
In web.config i have a uri reference to account.xml, here is account.xml
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net
http://www.springframework.net/xsd/spring-objects.xsd">
<object id="getContact" type="SpringNetService.getContact, SpringNetService">
</object>
<object id="AccountExporter" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName"><value>getContact</value></property>
<property name="Interfaces">
<list>
<value>SpringNetContract.IContact, SpringNetContract</value>
</list>
</property>
</object>
</objects>
When i trying to hit http://localhost/springnetservice/AccountExporter.asmx
I got the following error:
Could not load type SpringNetContract.IContact from assembly SpringNetContract, Version=1.0.2264.28573, Culture=neutral, PublicKeyToken=null.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.TypeLoadException: Could not load type SpringNetContract.IContact from assembly SpringNetContract, Version=1.0.2264.28573, Culture=neutral, PublicKeyToken=null.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[TypeLoadException: Could not load type SpringNetContract.IContact from assembly SpringNetContract, Version=1.0.2264.28573, Culture=neutral, PublicKeyToken=null.]
System.Reflection.Assembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase) +0
Spring.Util.TypeResolver.LoadTypeDirectlyFromAssem bly(TypeAssemblyInfo typeInfo)
Spring.Util.TypeResolver.Resolve(String typeName)
[TypeLoadException: Could not load type from string value 'SpringNetContract.IContact, SpringNetContract'.]
Spring.Util.TypeResolver.Resolve(String typeName)
Spring.Util.CachedTypeResolver.Resolve(String typeName)
Spring.Util.ReflectionUtils.ToInterfaceArray(Strin g[] interfaceNames)
Spring.Web.Services.WebServiceExporter.AfterProper tiesSet()
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.InvokeInitMethods(Object target, String name, IConfigurableObjectDefinition definition)
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching)
[ObjectCreationException: Error creating object with name 'AccountExporter' defined in 'file [c:\inetpub\wwwroot\SpringNetService\Config\Account .xml]' : Initialization of object failed : Could not load type from string value 'SpringNetContract.IContact, SpringNetContract'.]
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching)
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments)
Spring.Objects.Factory.Support.AbstractObjectFacto ry.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments)
Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name, Type requiredType, Object[] arguments)
Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name, Object[] arguments)
Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name)
Spring.Objects.Factory.Support.DefaultListableObje ctFactory.PreInstantiateSingletons()
Spring.Context.Support.AbstractApplicationContext. Refresh()
Spring.Context.Support.XmlApplicationContext..ctor (String name, Boolean caseSensitive, IApplicationContext parentContext, String[] configurationLocations)
Spring.Context.Support.XmlApplicationContext..ctor (String name, Boolean caseSensitive, String[] configurationLocations)
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.Reflection.RuntimeConstructorInfo.InternalI nvoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean isBinderDefault) +0
System.Reflection.RuntimeConstructorInfo.Invoke(Bi ndingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +398
System.Reflection.ConstructorInfo.Invoke(Object[] parameters) +14
Spring.Objects.ObjectUtils.InstantiateType(Constru ctorInfo constructor, Object[] arguments)
[FatalObjectException: Cannot instantiate Type [Spring.Context.Support.XmlApplicationContext] using ctor [Void .ctor(System.String, Boolean, System.String[])] : 'Exception has been thrown by the target of an invocation.']
Spring.Context.Support.WebApplicationContext.get_C urrent()
Spring.Web.Services.WebServiceHandlerFactory.Syste m.Web.IHttpHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String path)
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String requestType, String path, String pathTranslated, Boolean useAppConfig) +699
System.Web.MapHandlerExecutionStep.System.Web.Http Application+IExecutionStep.Execute() +95
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously) +173
Looks like it can't convert the business object. Do i have to do something special to make it work.
Thanks for any help.
Tony
Bruno Baia
03-14-2006, 10:46 PM
The error says it all :
"Could not load type SpringNetContract.IContact from assembly SpringNetContract"
There is no SpringNetContract.IContact, try SpringNetContract.IGetContact :)
-Bruno
I must be blind. It works very well. I created a new method to return me a list of Contacts, and without effect, I successfully bind the list of contacts to a datagrid.
Great job, SpringNet team.
Now, i am going to try to use AOP to inject some advice to my service layer.
Tony
Ater everything works fine in a typical web -->Interface --> Web service structure, I want to move some of my SpringNet awared web confguration into the Interface layer which meaning any web applilcation should be able to use my service even they don't have the springNet framework configured at the web client.
So, Here is what i did.
I remove all the web.config from the my web application leaves a nature .net web application.
The interface layer, I added a class called ContactHelper.cs which will call web service and get data.
using System;
namespace SpringNetContract
{
/// <summary>
/// Summary description for ContactHelper.
/// </summary>
public class ContactHelper
{
public ContactHelper()
{
//
// TODO: Add constructor logic here
//
}
#region public property
private IHelloWorld helloWorldService;
private SpringNetContract.IContact contactService;
private SpringNetContract.IAccount accountService;
public IHelloWorld HelloWorldService
{
set { helloWorldService = value; }
get {return helloWorldService;}
}
public IAccount AccountService
{
set { accountService = value; }
get {return accountService;}
}
public IContact ContactService
{
set { contactService = value; }
get {return contactService;}
}
#endregion
#region public method
public xo.Common.BusinessObject.ContactCollection GetXOContacts()
{
return ContactService.GetXOContacts();
}
#endregion
}
}
The app.config looks like this
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context type="Spring.Context.Support.XmlApplicationContext, Spring.Core">
<resource uri="~/Config/Contact_Dev.xml" />
</context>
</spring>
</configuration>
The Config/Contact_Dev.xml looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<object id="MyService" type="Spring.Web.Services.WebServiceClientFactory, Spring.Services">
<property name="ServiceUrl" value="http://localhost/SpringNetService/HelloWorld1Exporter.asmx" />
<property name="ServiceInterface" value="SpringNetContract.IHelloWorld, SpringNetContract" />
<property name="MessageBindings">
<dictionary>
<entry key="DisplayText()" value="MyHelloWorld" />
<entry key="DisplayText2()" value="MyHelloWorld2" />
</dictionary>
</property>
</object>
<object id="IAccountService" type="Spring.Web.Services.WebServiceClientFactory, Spring.Services">
<property name="ServiceUrl" value="http://localhost/SpringNetService/AccountExporter.asmx" />
<property name="ServiceInterface" value="SpringNetContract.IAccount, SpringNetContract" />
</object>
<object id="IContactService" type="Spring.Web.Services.WebServiceClientFactory, Spring.Services">
<property name="ServiceUrl" value="http://localhost/SpringNetService/ContactExporter.asmx" />
<property name="ServiceInterface" value="SpringNetContract.IContact, SpringNetContract" />
</object>
<object id=ContactHelper type="SpringNetContract.ContactHelper,SpringNetContract">
<property name="HelloWorldService" ref="MyService" />
<property name="AccountService" ref="IAccountService" />
<property name="ContactService" ref="IContactService" />
</object>
</objects>
When I run the application at the client whcih will call the ContactHelper.GetXOContacts(), somehow the property of ContactService in ContactHelper.cs get null reference which means I didn't get the configuration correct. What did I do wrong here?
Thanks,
Tony
Bruno Baia
03-20-2006, 06:22 PM
Hi Tony,
I think your config file "Contact_Dev.xml" is not loaded.
<context type="Spring.Context.Support.XmlApplicationContext, Spring.Core">
<resource uri="~/Config/Contact_Dev.xml" />
</context>
As you are using a referenced library, which access spring objects, from your web application, your file 'Config/Contact_Dev.xml' should be in the bin directory and not in the web application directory.
-Bruno
Bruno,
I moved the Config/Contact_Dev.xml to the bin dir of my Interface layer.
It still didn't work.
How do I reference a directory under the application root like I had
Config/Contact_Dev.xml in a class file? Does that
<resource uri="~/Config/Contact_Dev.xml" />
means looking for the root/Config/Contact_Dev.xml. If I want to keep the structure as it is (Config/ under the application root). How would you define the reference uri ?
Thanks a lot
Tony
Bruno Baia
03-20-2006, 09:03 PM
If I want to keep the structure as it is (Config/ under the application root). How would you define the reference uri ?
<resource uri="../Config/Contact_Dev.xml" />
another solution is to use embedded assembly configuration file in your class library, include your Contact_Dev.xml file as an embedded ressource in your class library :
<resource uri="assembly://AssemblyName/Namespace/FileName"/>
-Bruno
Bruno,
I tried it didn't work.
Looks like the app.config didn't fire at all. Since the interface is a class clibrary, does the app.config got fire. I am putting everying into the app.config.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context type="Spring.Context.Support.XmlApplicationContext, Spring.Core">
<resource uri="config://spring/objects" />
</context>
<objects xmlns="http://www.springframework.net">
<object id="MyService" type="Spring.Web.Services.WebServiceClientFactory, Spring.Services">
<property name="ServiceUrl" value="http://localhost/SpringNetService/HelloWorld1Exporter.asmx" />
<property name="ServiceInterface" value="SpringNetContract.IHelloWorld, SpringNetContract" />
<property name="MessageBindings">
<dictionary>
<entry key="DisplayText()" value="MyHelloWorld" />
<entry key="DisplayText2()" value="MyHelloWorld2" />
</dictionary>
</property>
</object>
<object id="IAccountService" type="Spring.Web.Services.WebServiceClientFactory, Spring.Services">
<property name="ServiceUrl" value="http://localhost/SpringNetService/AccountExporter.asmx" />
<property name="ServiceInterface" value="SpringNetContract.IAccount, SpringNetContract" />
</object>
<object id="IContactService" type="Spring.Web.Services.WebServiceClientFactory, Spring.Services">
<property name="ServiceUrl" value="http://localhost/SpringNetService/ContactExporter.asmx" />
<property name="ServiceInterface" value="SpringNetContract.IContact, SpringNetContract" />
</object>
<object id=ContactHelper type="SpringNetContract.ContactHelper,SpringNetContract">
<property name="HelloWorldService" ref="MyService" />
<property name="AccountService" ref="IAccountService" />
<property name="ContactService" ref="IContactService" />
</object>
</objects>
</spring>
</configuration>
Thanks.
Bruno Baia
03-20-2006, 09:59 PM
How looks your the bin/ directory of the web application ? (file listing)
In my bin: SprintNetContract.dll, xo.Common.BusinessObject.dll
Here is the structure of interface project(class clibrary):
SprintNetContract project
Config
Contact_Dev.xml
Bin
SprintNetContract.dll
xo.Common.BusinessObject.dll
AccountHelper.cs
IAccount.cs
IContact.cs
IHelloWorld.cs
App.config
Currently, I am not using Config/Contact_Dev.xml, I put everything in the app.config. It looks like the app.config never got initialized. I still have the no reference object error.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 42: {
Line 43: return ContactService.GetXOContacts();
Line 44: }
Line 45: #endregion
Line 46: }
Source File: c:\springnetexample\sample\springnetcontract\conta cthelper.cs Line: 44
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
SpringNetContract.ContactHelper.GetXOContacts() in c:\springnetexample\sample\springnetcontract\conta cthelper.cs:44
spring.WebForm1.Page_Load(Object sender, EventArgs e) in c:\springnetexample\sample\springnetwebclient\webf orm1.aspx.cs:50
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +739
Bruno Baia
03-21-2006, 03:39 PM
Hi Tony,
In my previous coments, I was talking about your main project, the one which gonna use your class library 'SpringNetContract' : The Web application SpringNetWebClient
With
<resource uri="config://spring/objects" />
Your Web application should look like this :
-- SpringNetWebClient
-- bin
-- SpringNetWebClient.dll
-- SpringNetContract.dll
-- SpringNetContract.dll.config <<-- copy the config file
-- ...
-Bruno
Hi, bruno
Thanks for the reply.
The whole purpose of moving all configuration from web client tier to the interface tier is that I want to make the web client(any client) doesn't have to be SpringNet aware. That said, my current web client is just another pure .net web application without any specific setting for SpringNet.
In my web client , I have the reference to the SprintNetContract project. The web.confg is just pure .net default web.config(no spring context,no httphandler etc)Then, I have webForm1.aspx, the code behind like this:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
ContactHelper helper=new ContactHelper();
this.datagrid1.DataSource=helper.GetXOContacts();
this.datagrid1.DataBind();
}
The Interface layer should then initialized the object based DI defined in the app.config. Is this acheivable?
Tony
Bruno Baia
03-21-2006, 04:29 PM
I understand what you want to do,
add a app.config file with the configuration i saw below to your SprinNetContract class library project.
It will generate a file 'SprinNetContract.dll.config' into the bin/debug (bin/release) directory, copy this file into the bin directory of the web application.
Your Web application should look like this :
-- SpringNetWebClient
-- bin
-- SpringNetWebClient.dll
-- SpringNetContract.dll
-- SpringNetContract.dll.config <<-- copy the config file
Another solution is to use embedded assembly configuration file in your class library, include your Contact_Dev.xml file as an embedded ressource in your class library.
No external config file to manage, but if you want to change something, u need to compile.
Something like that :
<resource uri="assembly://SpringNetContract/SpringNetContract.Config/Contact_Dev.xml"/>
-Bruno
Thanks, Bruno
I tried the second approach with embeded resource. Here is what I did.
1. I set the SpringNetContract layer Config/Contact_Dev.xml as embbed resource.
2. On my web client, the web.config looks like this:
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context type="Spring.Context.Support.WebApplicationContext, Spring.Web">
<resource uri="config://spring/objects" />
<resource uri="assembly://SpringNetContract/SpringNetContract.Config/Contact_Dev.xml" />
</context>
</spring>
<system.web>
<httpHandlers>
<add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web" />
</httpHandlers>
...
I still have to put <httpHandlers>
<add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web" />
</httpHandlers>
Otherwise, I don't have sprintNet context object. Is there anyway to get around it.
After i run it, I got something like that:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Spring.Core.IO.ConfigSectionResource.get_InputStre am() in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Core\IO\ConfigSectionResource.cs:200
Spring.Objects.Factory.Xml.XmlObjectDefinitionRead er.LoadObjectDefinitions(IResource resource) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Xml\XmlObjectDefinitionReader.cs :144
Spring.Context.Support.AbstractXmlApplicationConte xt.LoadObjectDefinitions(XmlObjectDefinitionReader objectDefinitionReader) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Context\Support\AbstractXmlApplicationContext.cs :203
Spring.Context.Support.AbstractXmlApplicationConte xt.RefreshObjectFactory() in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Context\Support\AbstractXmlApplicationContext.cs :122
Spring.Context.Support.AbstractApplicationContext. Refresh() in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Context\Support\AbstractApplicationContext.cs:75 6
Spring.Context.Support.WebApplicationContext..ctor (String name, Boolean caseSensitive, IApplicationContext parentContext, String[] configurationLocations) in c:\projects\daily\Spring.Net\src\Spring\Spring.Web \Context\Support\WebApplicationContext.cs:89
Spring.Context.Support.WebApplicationContext..ctor (String name, Boolean caseSensitive, String[] configurationLocations) in c:\projects\daily\Spring.Net\src\Spring\Spring.Web \Context\Support\WebApplicationContext.cs:69
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.Reflection.RuntimeConstructorInfo.InternalI nvoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean isBinderDefault) +0
System.Reflection.RuntimeConstructorInfo.Invoke(Bi ndingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +398
System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
Spring.Objects.ObjectUtils.InstantiateType(Constru ctorInfo constructor, Object[] arguments) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\ObjectUtils.cs:162
[FatalObjectException: Cannot instantiate Type [Spring.Context.Support.WebApplicationContext] using ctor [Void .ctor(System.String, Boolean, System.String[])] : 'Exception has been thrown by the target of an invocation.']
Spring.Context.Support.WebApplicationContext.get_C urrent() in c:\projects\daily\Spring.Net\src\Spring\Spring.Web \Context\Support\WebApplicationContext.cs:127
Spring.Web.Support.PageHandlerFactory.GetHandler(H ttpContext context, String requestType, String url, String path) in c:\projects\daily\Spring.Net\src\Spring\Spring.Web \Web\Support\PageHandlerFactory.cs:69
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String requestType, String path, String pathTranslated, Boolean useAppConfig)
System.Web.MapHandlerExecutionStep.System.Web.Http Application+IExecutionStep.Execute()
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously)
Any idea?
Tony
Bruno Baia
03-22-2006, 05:23 PM
If you don't use Web application anymore with Spring.NET, are you retrieving somewhere the Spring Context ?
IApplicationContext ctx = ContextRegistry.GetContext();
Example, with a static method :
public static xo.Common.BusinessObject.ContactCollection GetXOContacts()
{
IApplicationContext ctx = ContextRegistry.GetContext();
ContactHelper helper = ctx.GetObject("ContactHelper");
return helper.ContactService.GetXOContacts();
}
-Bruno
I didn't have code to retrieve the spingNet context. I though you can't get the springNet context if you are not using SpringNet framework configuration to initlize the SpringNet context object. I orgnial plan to initlize the context object in interface layer, it won't work since it is the class library being reference by the web layer. So, what are the alternative left for me? How can I reference the object defined in xml? using objectwrapper?
Tony
Bruno Baia
03-23-2006, 04:19 PM
Hi,
You should be able to do that using directly an IApplicationContext implementation :
XmlApplicationContext ctx = new XmlApplicationContext("assembly://SpringNetContract/SpringNetContract.Config/Contact_Dev.xml");
-Bruno
It worked.
I am going to post another question regarding how to incorporate springnet web service with WSE2(secure your web service).
Great help. Thanks
It worked always the first run. But I got trouble after refresh or post the page.
I got message like this
Duplicate type name within an assembly.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Duplicate type name within an assembly.
Source Error:
Line 50: if (!Page.IsPostBack)
Line 51: {
Line 52: XmlApplicationContext ctx = new XmlApplicationContext("assembly://SpringNetContract/SpringNetContract.Config/Contact_Dev.xml");
Line 53: SpringNetContract.ContactHelper helper=(SpringNetContract.ContactHelper)ctx.GetObj ect("contactHelper");
Line 54:
Source File: c:\springnetexample\sample\springnetwebclient\webf orm2.aspx.cs Line: 52
Stack Trace:
[ArgumentException: Duplicate type name within an assembly.]
System.Reflection.Emit.AssemblyBuilderData.CheckTy peNameConflict(String strTypeName, TypeBuilder enclosingType) +312
System.Reflection.Emit.TypeBuilder.Init(String fullname, TypeAttributes attr, Type parent, Type[] interfaces, Module module, PackingSize iPackingSize, Int32 iTypeSize, TypeBuilder enclosingType) +176
System.Reflection.Emit.TypeBuilder..ctor(String name, TypeAttributes attr, Type parent, Type[] interfaces, Module module, PackingSize iPackingSize, TypeBuilder enclosingType) +28
System.Reflection.Emit.ModuleBuilder.DefineType(St ring name, TypeAttributes attr, Type parent) +88
Spring.Proxy.CompositionProxyTypeBuilder.CreateTyp eBuilder() in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Proxy\CompositionProxyTypeBuilder.cs:198
Spring.Web.Services.SoapHttpClientProxyTypeBuilder .BuildProxy() in c:\projects\daily\Spring.Net\src\Spring\Spring.Ser vices\Web\Services\WebServiceClientFactory.cs:505
Spring.Web.Services.WebServiceClientFactory.Genera teProxy() in c:\projects\daily\Spring.Net\src\Spring\Spring.Ser vices\Web\Services\WebServiceClientFactory.cs:334
Spring.Web.Services.WebServiceClientFactory.GetObj ect() in c:\projects\daily\Spring.Net\src\Spring\Spring.Ser vices\Web\Services\WebServiceClientFactory.cs:263
Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObjectForSharedInstance(String name, Object instance) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractObjectFactory.cs :596
[ObjectCreationException: Error thrown by a dependency of object 'contactHelper' defined in 'assembly [SpringNetContract, Version=1.0.2287.27783, Culture=neutral, PublicKeyToken=null], resource [SpringNetContract.Config.Contact_Dev.xml]' : IFactoryObject threw exception on object creation.
while resolving 'HelloWorldService' to '' ]
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.ResolveReference(IConfigurableOb jectDefinition definition, String name, String argumentName, RuntimeObjectReference reference) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:1703
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.ResolveValueIfNecessary(String name, RootObjectDefinition definition, String argumentName, Object argumentValue) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:1584
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.ApplyPropertyValues(String name, RootObjectDefinition definition, IObjectWrapper wrapper, IPropertyValues properties) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:290
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.PopulateObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:394
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:745
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:609
Spring.Objects.Factory.Support.AbstractObjectFacto ry.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractObjectFactory.cs :1259
Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name, Type requiredType, Object[] arguments) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractObjectFactory.cs :234
Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name, Object[] arguments) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractObjectFactory.cs :1203
Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractObjectFactory.cs :1163
Spring.Objects.Factory.Support.DefaultListableObje ctFactory.PreInstantiateSingletons() in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\DefaultListableObjectFac tory.cs:462
Spring.Context.Support.AbstractApplicationContext. Refresh() in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Context\Support\AbstractApplicationContext.cs:78 9
Spring.Context.Support.XmlApplicationContext..ctor (String name, Boolean caseSensitive, IApplicationContext parentContext, String[] configurationLocations) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Context\Support\XmlApplicationContext.cs:181
Spring.Context.Support.XmlApplicationContext..ctor (String[] configurationLocations) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Context\Support\XmlApplicationContext.cs:94
springTest.WebForm2.Page_Load(Object sender, EventArgs e) in c:\springnetexample\sample\springnetwebclient\webf orm2.aspx.cs:52
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
Any ideas?
Thanks
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.