PDA

View Full Version : "Object reference not set to an instance of an object"


cwienands
12-21-2006, 11:44 PM
Hey guys,

I'm pretty much lost right now. I'm trying to do dependency injection for web services but whatever I do is getting a "Object reference not set to an instance of an object" exception when I navigate to that web service in the web browser. I'm not even at the point where the dependency gets injected but rather it's somewhere in the WebServiceHandlerFactory. Here is what I have:

Stack trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Spring.Web.Services.WebServiceHandlerFactory.Syste m.Web.IHttpHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String path) +87
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +328
System.Web.MapHandlerExecutionStep.System.Web.Http Application.IExecutionStep.Execute() +139
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously) +146


In web.config:
<httpHandlers>
<add verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web"/>
</httpHandlers>


In SpringConfiguration.xml:
<object name="TestService" type="AISWebService.Test, AISWebService" abstract="false"/>

<object id="Test.asmx" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName" value="TestService"/>
<property name="Namespace" value="http://SpringWS/WebServices"/>
</object>


Test.cs
namespace AISWebService
{
public class Test : ITest
{
[WebMethod]
public void HelloWorld()
{
}
}

public interface ITest
{
void HelloWorld();
}
}

Global.asax
IApplicationContext context = new XmlApplicationContext("assembly://AISWebService/AISWebService/SpringConfiguration.xml");

I'm using Spring 1.0.2. I did some tests and the application context gets properly initialized. Beside that I have no idea why the WebServiceHandlerFactory somehow craps out.

Does anybody here have a clue what I'm doing wrong? By the way, I got the same problem when working without the WebServiceExporter.

Thanks a million, Christoph

cwienands
12-22-2006, 02:22 PM
By the way, I just switched over to the latest binaries of Spring 1.1 and got the same results. It seems I'm doing something fundamentally wrong :-(

Christoph

Erich Eichinger
12-22-2006, 04:23 PM
Hi,

WebServiceExporter uses Spring.Web's WebApplicationContext infrastructure for DI. You should configure your web as described in this guide (http://forum.springframework.net/showthread.php?t=697). (Note that the Reference Docs are unfortunately not up2date yet regarding Spring.Web).

Remove your manual context initialization code from Global.asax and configure your context within web.config:


<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context"
type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
</sectionGroup>
</configSections>

<httpModules>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web" />
</httpModules>

<httpHandlers>
<add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web" />
<add verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web" />
</httpHandlers>

<spring>
<context>
<resource uri="assembly://AISWebService/AISWebService/SpringConfiguration.xml" />
</context>
</spring
</configuration>


cheers,
Erich