WSE Policy

Topics: CAB & Smart Client Software Factory
Mar 3, 2006 at 6:27 AM
originally posted by: mbpublic

How does one use WSE 3 Policy with Smart Web Reference?
Aug 3, 2006 at 12:58 AM
originally posted by: shahramjam

Well this is wierd,Using WSE in smart client is the most basic that you need to do and yet no answer and no doc about this issue.Somebody from P&P team please answer this question!

Aug 4, 2006 at 7:46 AM
originally posted by: austinlamb

I'm currently working on integrating WSE 3 and SCSF. I will hopefully be able to post in a couple weeks with my progress (I've just gone on vacation, so don't have access to any of my work source files).

The "best" way would, in all probability, be to modify the guidance package to have the templates ask for policy names or something like that, and apply those for you. But, if you want to stay out of modifying the GP, and just hand-edit the code that comes out the other side, here's my first suggestion:

Make another file somewhere in the project that has the smart web references. Call it something like "ServicePolicies.cs" (or whatever you wish), and then put things like this in for each service you're calling:

namespace NamespaceOfService.Goes.Here {

public partial class ServiceClassNameHereWse {


Note that I put "Wse" at the end of the service class name. That'd be important.

Then, you may need to edit the Smart Web Reference output (as I recall) to make it reference ServiceClassNameHereWse instead of ServiceClassNameHere.

That should be about all you'd need, though, to get the basics up and going? Then you could use SetClientCredential<T> and other methods to get your security tokens attached, and go from there.

Does that help?
Aug 4, 2006 at 10:46 AM
originally posted by: shahramjam

Thank you for your answer, it really helps, but one question:How Policy("MyPolicyName") works?
Aug 4, 2006 at 12:28 PM
originally posted by: austinlamb

I'm just using the standard WSE 3.0 PolicyAttribute there, nothing custom. I suggest seeing the WSE 3.0 documentation and quickstarts for a more thorough explanation than I could possibly give here.
Apr 19, 2007 at 2:00 AM
Edited Apr 19, 2007 at 9:00 PM
Can anyone add to this thread and pass on a few hints on how they set up WSE 3.0
I have a Web Service and a SmartClient and I’m thinking I want to use UserNameToken (unless someone has a better idea?)

All input – gratefully received?
Apr 27, 2007 at 10:49 PM
Can anyone advise that they have successfully set up WSE 3.0 on a Smart Client application?
Apr 28, 2007 at 10:35 PM
Take a look at this

Apr 30, 2007 at 5:48 PM
I have a SCSF app that uses WSE 3.0 successfully. It uses code like the following:
MyServiceWse svc;
UsernameToken userToken = new UsernameToken(uid, pwd, PasswordOption.SendPlainText)
svc.SetPolicy("MyPolicyName"); // defined in the WSE config file

When you point to a Web Service URL that has been built with WSE and you use the SCSF guidance package to "Add a Smart Web Reference" for "MyService" to your project, the following classes will be generated:


The first of these classes, MyServiceWse, will be located under "WebReferences" in the Reference.cs file (you may have to click on the "Show All Files" button to see this file. One "gotcha" I have found is that I have to make a minor change to this Reference.cs file every time I generate it (though you could change your guidance package, I just haven't done this yet). I change the following line, adding the inheritance from IMyService:

public partial class MyServiceWse : Microsoft.Web.Services3.WebServicesClientProtocol, IMyService

(In my apps I create a wrapper class around each ServiceProxy class to handle setting the URL dynamically, setting the WSE as shown above, etc. I can post the base class for this wrapper if anyone would like it. But it may be best to keep it simple until you have it working and understand how you need to set things up.)

I agree that it was not very intuitive and definitely not trivial to add WSE support to my SCSF app, especially adding it in a way that does not bloat my code. But I think with the use of the base class I mentioned, I was able to do it and turns out to be pretty slick...
(The Patterns and Practices group should consider that many people will use SCSF, WSSF, and WSE in conjunction with each other. It seems like there is not enough coordination between these three tools/products.)

If I left anything out, let me know and I can post more info...
May 1, 2007 at 4:05 AM
Hi tonderum, could you please post the wrapper class? I think it would help with a problem I've been having getting WSE working with Smart Web References and Service Agents that access the web service proxies.
Jun 5, 2007 at 2:56 PM
Hi tonderum,

Can you give some more detailed insight of how to use WSE within SCSF by posting some sample code? As I m in very urgent need of implementing the same.