PDA

View Full Version : Complex Types: Combining GenerateScriptTypeAttribute with WebServiceExporter



K-Mile
07-26-2007, 08:01 PM
Hi,

I've been trying to create webservices that accept objects that have complex types as members, and even abstract types, since our application relies heavily on them. What we need is a way to enable communications in these objects (so we need to resolve the concrete class, but that's what '__type' is for, right?).

As seen in http://ajax.asp.net/docs/mref/T_System_Web_Script_Services_GenerateScriptTypeAtt ribute.aspx

this should be doable, as long as we can attach the attribute to the webservice proxy. This should be easy to do with spring:

<property name="TypeAttributes">
<list>
<object type="System.Web.Script.Services.ScriptServiceAttribute, System.Web.Extensions"/>
<expression value="@[GenerateScriptTypeAttribute(typeof(MyCustomClass))]"/>
</list>
</property>

I've also tried the T() way of inserting the type, instead of typeof()...

I have been going through the ASP.NET AJAX source to figure out how they resolve the types internally, but this code is totally not extensible. But I'm pretty sure the attribute above should do the trick, however...

I've been getting 'Value should not be null, property name type' errors, no matter how I implement the attribute loading (expression, object instantiation, downright adding the attribute to my service)

Does anyone have any insights, or has this working?

Thanks!

Bruno Baia
07-26-2007, 08:28 PM
Hi,

this is an known bug (see SPRNET-606 (http://opensource.atlassian.com/projects/spring/browse/SPRNET-606)) resolved since 1.1 M2.
Give it a try and let us know.



I've also tried the T() way of inserting the type, instead of typeof()...

The T() way is the good one.


- Bruno

K-Mile
07-27-2007, 12:05 AM
Thanks Bruno, I'll give it a shot right away!

K-Mile
07-27-2007, 02:12 AM
The situation described in the ticket and forum posts match my case exactly. However, the problem is not yet solved. If I step through the code, it still does not send any constructor arguments to the attribute.



if (ci == null && ctorArgs.Length == 0)
{
ci = type.GetConstructors()[0];
ctorArgs = GetDefaultValues(GetParameterTypes(ci.GetParameter s()));
}

if (sourceAttribute != null)
{
object defaultAttribute = ci.Invoke(ctorArgs);
[...]
}

This is where things go bad, in ReflectionUtils around line 650. I've been looking at the fix regarding SPRNET-606, but I fail to see how this resolves this specific problem for this Attribute. I would expect that some knowledge about what properties of the original attribute are required as constructor arguments is necessary to fix this problem. Am I overlooking something?

K-Mile
07-27-2007, 03:04 AM
I made it work, for our situation, although this might be one of the dirtiest ways I've coded in a long way. Needed to see if the attribute worked eventually, and it did.

I just caught any exceptions invoking the attribute constructor, and set the appropriate parameter that the exception reported as null. Rinse and repeat until every parameter is processed or the constructor invoking succeeds.

Anyway, I'll leave checking if this is still an issue, or its just me doing something wrong, to you guys. Let me know if I can be of any help providing some more information about my specific case.

Bruno Baia
07-27-2007, 11:13 AM
This is where things go bad, in ReflectionUtils around line 650. I've been looking at the fix regarding SPRNET-606, but I fail to see how this resolves this specific problem for this Attribute. I would expect that some knowledge about what properties of the original attribute are required as constructor arguments is necessary to fix this problem. Am I overlooking something?
With 1.41 version, see code since line 683 :
http://fisheye1.cenqua.com/browse/springnet/Spring.Net/src/Spring/Spring.Core/Util/ReflectionUtils.cs?r=1.41

which version are you using ?


Bruno

K-Mile
07-31-2007, 03:55 PM
With 1.41 version, see code since line 683 :
http://fisheye1.cenqua.com/browse/springnet/Spring.Net/src/Spring/Spring.Core/Util/ReflectionUtils.cs?r=1.41

which version are you using ?


Bruno

I am using the M2 from the download page, and the code you've shown is in there, but my problem happens at line 653, directly at the invoke statement there.

Bruno Baia
08-01-2007, 12:40 AM
Hi,

You right, this is a bug.
I commited a fix and test for that.

Give a try to the latest nightly build (Spring.NET-20070731-2222.zip) or wait for the RC1.


- Bruno

K-Mile
08-06-2007, 04:32 PM
Thanks Bruno, I will give it a shot when I have a chance.

arahman
09-17-2008, 05:00 AM
K-Mile, did you manage to get this running?

Anyone has any idea on getting the GenerateScript attribute to work with a class in another assembly?

Thanks.