PDA

View Full Version : Exposing a method with EnableSession as a Web Service


dimitrod
05-10-2006, 11:51 AM
Hello,

I am trying to expose a service class as a Web Service using the Spring.Web.Services.WebServiceExporter class. I have managed to achieve this but the only way I found so far to enable session support in the methods was to add the [WebMethod (EnableSession=true)] attribute to each method. Is there a way to enable session support for certain methods or maybe for all methods in the object using the spring configuration file? Here is my config:

<object name="WsTest" type="WsTest.WsTest, WsTest" />

<object id="WsTestExporter"
type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName" value="WsTest" />
<property name="Namespace" value="http://test/WS"/>
<property name="Description" value="My Description"/>
<property name="Interfaces">
<list>
<value>WsTest.IWsTest, WsTest</value>
</list>
</property>
</object>


Thanks in advance,

Darin

Bruno Baia
05-10-2006, 12:52 PM
Hi Darin,

you can "inject" the WebMethod attribute like that :


<object id="WsTestExporter" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName" value="WsTest" />
<property name="Namespace" value="http://test/WS"/>
<property name="Description" value="My Description"/>
<property name="Interfaces">
<list>
<value>WsTest.IWsTest, WsTest</value>
</list>
</property>

<property name="Methods">
<dictionary>
<entry key="*">
<object type="System.Web.Services.WebMethodAttribute, System.Web.Services">
<property name="EnableSession" value="true"/>
</object>
</entry>
</dictionary>
</property>

</object>



-Bruno

dimitrod
05-10-2006, 01:01 PM
Thanks Bruno,

That's really cool!!

Bruno Baia
05-10-2006, 01:03 PM
Btw, the "WsTest" object exported as a web service is defined as a singleton, so the same instance will be use for the web service.
For some cases, you can use private field instead of using Session.

-Bruno

dimitrod
05-10-2006, 01:46 PM
Btw, the "WsTest" object exported as a web service is defined as a singleton, so the same instance will be use for the web service.
For some cases, you can use private field instead of using Session.

Bruno,

My service object is defined as a singleton and I cannot use private field because that would mean that every caller of the service will share the same instance. What I need to do is to store some user specific information. On the other hand if I define the object as non singleton then every successive call would create a new instance and I won't be able to persist user specific data. That's why I decided to use sessions.


Btw, what you suggested me for injecting WebMethod attribute works perfect in Cassini Web Server but when I deployed my application on IIS, HttpContext.Current.Session = null once again and I had to explicitly add the attribute to every single method I use in order to obtain session support. Do you have any idea what could be wrong?

Thanks for your time,

Darin

dimitrod
05-10-2006, 02:12 PM
I found the error with WebMethodAttribute, it was a nasty typo mistake I did :-), now everything works like charm.

Mark Pollack
05-10-2006, 03:00 PM
Hi,

Just curious if you could provide the silly details of the type as I'd like to understand if a custom schema for the exporter would have help catch it via xml validation.

Cheers,
Mark

Bruno Baia
05-10-2006, 03:29 PM
Darin, are you using the wildcard or the name of the method to match the method that needs session enabled ?

I tried "*" and it's not working, i added a description to my methods to see when it works :

<object type="System.Web.Services.WebMethodAttribute, System.Web.Services">
<property name="Description" value="Spring web test method"/>
<property name="EnableSession" value="true"/>
</object>



-Bruno

dimitrod
05-10-2006, 06:35 PM
Bruno,

I used the method name in order to match successfully. The wildcard didn't work for me. And if the method has arguments it is more tricky:


<entry key="ArgumentlessMethod">
<object type="System.Web.Services.WebMethodAttribute,
System.Web.Services">
<property name="EnableSession" value="true"/>
</object>
</entry>
<entry key="MethodWithArguments(int, string)">
<object type="System.Web.Services.WebMethodAttribute,
System.Web.Services">
<property name="EnableSession" value="true"/>
</object>
</entry>

Bruno Baia
05-11-2006, 12:13 AM
Hi,

Yeah, this needs some changes, we are waiting for the new aop pointcut language to match the right method, but i need this to work for the WSE integration, so I'll try to implement something using regular expressions or the new expression language for now.

i'll ping back here.


-Bruno

Bruno Baia
09-11-2006, 03:30 PM
Hi Darin,

I implemented a fix for the wildcard bug with the WebServiceExporter.
You can also apply other attributes than WebMethodAtribute with the WebServiceExporter now.

-Bruno