View Full Version : Applying Microsoft.Web.Service3.PolicyAttribute to class
devcol
11-10-2006, 05:25 PM
Hi,
I am currently working with WSE 3.0 to add security to Spring generated web services via the Spring.Web.Services.WebServiceExporter.
I haven’t found an easy way of applying the Microsoft.Web.Services3.PolicyAttribute via the WebServiceExporter to the class without modifying the actual WebServiceExporter source code.
The classes that I am exporting have no reference to the Microsoft.Web.Services3 assembly. I do not intend to add a reference either.
Is there a proposed methodology for using WSE3.0 security with Spring exported WebServices and the Microsoft.Web.Services3.PolicyAttribute?
Example:
My Hello world class:
public class HelloWorld
{
....
Using WSE3.0 a policy an attribute is added [Policy("ServerPolicy")]:
using Microsoft.Web.Services3;
[WebService(Namespace = "http://company.com/samples/wse/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[Policy("ServerPolicy")]
public class HelloWorld: System.Web.Services.WebService
{
....
But with Spring the configuration is:
<object id="HelloWorldExporter"
type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName" value="HelloWorld"/>
<property name="Namespace" value="http://myCompany/services"/>
<property name="Description" value="My exported HelloWorld web
service"/>
<property name="Methods">
<dictionary>
<entry key="HelloWorld">
<object type="System.Web.Services.WebMethodAttribute,
System.Web.Services">
<property name="Description" value="My Spring-
configured HelloWorld method."/>
<property name="MessageName" value="ZdravoSvete"/>
</object>
</entry>
</dictionary>
</property>
</object>
How would I configure Spring to apply a policy attribute to my HelloWorld class and keep my class decoupled from Microsoft.Web.Services3?
My solution is attached. Modified WebServiceExporter.
Aleks Seovic
11-11-2006, 06:06 PM
You are absolutely right -- there is no way to add custom type-level attributes at the moment, even though they can be easily supported by the base proxy builder.
I'll add this as an improvement request to JIRA, and will probably implement it along the lines of what you sent, with one difference: instead of PolicyName property, which is specific to WSE, I will add TypeAttributes property which can be set to a list of type-level attributes that need to be defined on the proxy class.
Thanks,
Aleks
Bruno Baia
11-14-2006, 01:28 AM
Hi,
Done, the fix will be in the next nightly build.
As a note, "Method" property has changed to "MemberAttributes"
<object id="HelloWorldExporter" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName" value="HelloWorld"/>
<property name="Namespace" value="http://myCompany/services"/>
<property name="Description" value="My exported HelloWorld web service"/>
<property name="TypeAttributes">
<list>
<object type="Microsoft.Web.Services3.PolicyAttribute, Microsoft.Web.Services3">
<constructor-arg index="0" value="ServerPolicy"/>
</object>
</list>
</property>
<property name="MemberAttributes">
<dictionary>
<entry key="HelloWorld">
<object type="System.Web.Services.WebMethodAttribute, System.Web.Services">
<property name="Description" value="My Spring-configured HelloWorld method."/>
<property name="MessageName" value="ZdravoSvete"/>
</object>
</entry>
</dictionary>
</property>
</object>
Bruno
devcol
11-14-2006, 08:43 PM
Okay, that was really quick. I am trying to test this fix and I am currently having problems applying a policy to the WebService.
Our web services are currently not production ready and won't be for a while but it was very important to test the implications of using the Microsoft Web Service Enhancements 3.0 with Spring. WSE3.0 makes it easier to apply some WS-Security techniques to Web Services. I have been looking into applying an X.509 certificate policy.
I am getting a PolicyAttribute creation exception about it expecting a type argument. I've had this error in my original solution and fixed it by creating the attribute using Spring.Util.ReflectionUtils.CreateCustomAttribute( Type,object[]) e.g. Spring.Util.ReflectionUtils.CreateCustomAttribute( typeof(Microsoft.Web.Services3.PolicyAttribute), "ServerPolicy")
I'll post more detail when I can. ;)
Bruno Baia
11-14-2006, 10:13 PM
Hi,
FYI, there is an integration project for WSE2 under the sandbox :
"sandbox\Integrations\Spring.Web.Services2"
You can get it from any nightly build (http://www.springframework.net/downloads/nightly).
This will show you how to use Spring.Core, Spring.Aop and Spring.Services to integrate nicely Microsoft's WSE.
Hope this helps,
Bruno
spmva
10-22-2008, 11:45 PM
Hate to bring up old stuff...but...I'm having a problem similar to what devcol ran into many years ago and I can't seem to find the solution. Specifically, I'm seeing:
I am getting a PolicyAttribute creation exception about it expecting a type argument.
I get this exception (truncated a bit):
System.Web.Services.Protocols.SoapHeaderException: System.Web.Services.Protocols.SoapHeaderException: Server unavailable, please try later ---> System.ApplicationException: WSE842: The service pipeline could not be created. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: policyType
at Microsoft.Web.Services3.PolicyAttribute..ctor(Type policyType)
at System.Reflection.CustomAttribute._CreateCaObject( Void* pModule, Void* pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
at System.Reflection.CustomAttribute.CreateCaObject(M odule module, RuntimeMethodHandle ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)
at System.Reflection.CustomAttribute.GetCustomAttribu tes(Module decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes)
at System.Reflection.CustomAttribute.GetCustomAttribu tes(RuntimeType type, RuntimeType caType, Boolean inherit)
at System.RuntimeType.GetCustomAttributes(Boolean inherit)
at Microsoft.Web.Services3.Pipeline.TryCreate(Type type, Boolean forClient)
at Microsoft.Web.Services3.Pipeline.TryCreateForServi ce(Type type)
at Microsoft.Web.Services3.WseProtocol.CreateProtocol Pipeline()
at Microsoft.Web.Services3.WseProtocol.RouteRequest(S oapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.I nitialize()
at System.Web.Services.Protocols.ServerProtocolFactor y.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
It's puzzling because I've tried all manner of object creation to properly define the PolicyAttribute:
<property name="TypeAttributes">
<list>
<object type="Microsoft.Web.Services3.PolicyAttribute, Microsoft.Web.Services3">
<constructor-arg name="policyName" value="ServerPolicy"/>
</object>
</list>
</property>
<property name="TypeAttributes">
<list>
<object type="Microsoft.Web.Services3.PolicyAttribute, Microsoft.Web.Services3">
<constructor-arg type="string" value="ServerPolicy"/>
</object>
</list>
</property>
<property name="TypeAttributes">
<list>
<object type="Microsoft.Web.Services3.PolicyAttribute, Microsoft.Web.Services3">
<constructor-arg index="0" value="ServerPolicy"/>
</object>
</list>
</property>
All three of those options still produce that exception above when I try to make a call to the service and that error seems to indicate that the constructor for the PolicyAttribute being called is the one with the "policyType" parameter of type "Type".
Any ideas? I'd be happy to hear that I was doing something stupid.
spmva
10-23-2008, 12:21 PM
I didn't really solve the problem, but came up with a cheat. I created a PolicyAttributeFactory:
public class PolicyAttributeFactory
{
public static PolicyAttribute Create()
{
return new PolicyAttribute("ServerPolicy");
}
}
and then referenced in the TypeAttributes:
<object id="WseServerPolicy" type="MyNamespace.PolicyAttributeFactory" factory-method="Create"/>
<property name="TypeAttributes">
<list>
<list>
<ref object="WseServerPolicy"/>
</list>
</list>
</property>
not pretty by any means, but it appears to have moved me past that problem. I'm not sure why I had to do that, but at least it's a workaround.
dsmalley
11-17-2008, 07:28 PM
I have been stumped trying to use WSE 3.0 with Spring, particularly the WebServiceExporter. It seems it should be a straightforward matter of exporting the service and then applying the policy attribute with "TypeAttributes", but I just can't get it to work.
The only way I have been able to get a WSE 3.0 service exported was to apply the policy attribute directly to my service implementation class. This class is otherwise a PONO, it doesn't inherit from System.Web.Services.WebService, nor does it have any other attributes on the type or members.
While this dependency on Microsoft.Web.Services3 is irritating, I decided to live with it. I get the other benefits of Spring web services like the elimination of .asmx files. But I really wish I knew why it doesn't work "correctly".
I know, of course, that WSE 3.0 is old news, and WCF plays much nicer with Spring, but I happen to have one legacy system where upgrading to .NET 3.0 or 3.5 isn't an option right now, and I needed WS-Security extensions for one of the web services.
Dave
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.