Want to show your appreciation?
Please a cup of tea.

Friday, August 15, 2008

Spring.Net object name for Web Services

With the great experience that I have with Spring for Java for many years, I naturally started our .Net project with Spring.Net as the dependency injection framework. Overall this is another great experience. With that being said, we did encountered some difficulties here and there. This one is about the object name of the Web Service client. Let's say we have IHelloWorld and its implementation HelloWorld, thus we have the object defined in the spring.config as

<object id="HelloWorld" type="Example.Service.HelloWorld, Example.Service"/>

Of course, the HelloWorld ASP.NET page is working perfectly well with the injected IHelloWorld. Now we need to expose it as Web Service at HelloWorld.asmx. In order to do this, I must define the object name as 'HelloWorld'. There is no other way to expose the service as HelloWorld.asmx. This is bad. I obviously want to define the object id as HelloWorld.asmx like below:

  <object id="HelloWorld.asmx" type="WebServiceExporter">

    <property name="TargetName" value="HelloWorld"/>

    <property name="Namespace" value="http://imm.bn-corp.com/"/>

    <property name="Description" value="My exported Person web service"/>

    <property name="Name" value="HelloWorld"/>

  </object>

But this didn't work. The WebServiceHandlerFactory refused to pick it up. Solution? That's why I love the open source! Hey, we have the source code and all we did was to change the code in the factory class to the following. Everything started working happily.

string pageName = WebUtils.GetPageName(url);

IApplicationContext appContext = WebApplicationContext.Current;

 

string serviceName = pageName + ".asmx";

bool found = appContext.ContainsObjectDefinition(serviceName);

if (!found)

{

    serviceName = pageName;

    found = appContext.ContainsObjectDefinition(serviceName);

}

No comments:

Post a Comment