SetPolicy Exception while using NUnit

N

nyathancha

Hi,
I am using WSE to implement security using x509 certificates. This
works when I use a windows client but throws an exception when I use
NUnit.

My Code looks as follows :
UsernameToken myCurrentToken = new UsernameToken("xxxx", "YYY",
PasswordOption.SendPlainText);
MyServicesWse adminServices = new MyServicesWse();

adminServices.SetClientCredential<UsernameToken>(myCurrentToken);
adminServices.SetPolicy("ClientPolicy");

The App.Config has

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="microsoft.web.services3"
type="Microsoft.Web.Services3.Configuration.WebServicesConfiguration,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="{ModuleNamespace}.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
<section name="{ModuleNamespace}.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</sectionGroup>
</configSections>

<microsoft.web.services3>
<security>
<x509 allowTestRoot="true" storeLocation="CurrentUser" />
</security>
<tokenIssuer>
<statefulSecurityContextToken enabled="true" />
</tokenIssuer>
<messaging>
<mtom clientMode="On" />
</messaging>
<policy fileName="wse3policyCache.config" />
</microsoft.web.services3>

<applicationSettings>
... [Web Reference]
</applicationSettings>
</configuration>

and the wse3policyCache.config file has

<policies xmlns="http://schemas.microsoft.com/wse/2005/06/policy">
<extensions>
<extension name="usernameForCertificateSecurity"
type="Microsoft.Web.Services3.Design.UsernameForCertificateAssertion,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
<extension name="x509"
type="Microsoft.Web.Services3.Design.X509TokenProvider,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
<extension name="requireActionHeader"
type="Microsoft.Web.Services3.Design.RequireActionHeaderAssertion,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
</extensions>
<policy name="ClientPolicy">
<usernameForCertificateSecurity establishSecurityContext="true"
renewExpiredSecurityContext="true"
requireSignatureConfirmation="false"
messageProtectionOrder="SignBeforeEncrypt" requireDerivedKeys="true"
ttlInSeconds="300">
<serviceToken>
<x509 storeLocation="CurrentUser" storeName="AddressBook"
findValue="CN=WSE2QuickStartServer"
findType="FindBySubjectDistinguishedName" />
</serviceToken>
<protection>
<request signatureOptions="IncludeAddressing,
IncludeTimestamp, IncludeSoapBody" encryptBody="true" />
<response signatureOptions="IncludeAddressing,
IncludeTimestamp, IncludeSoapBody" encryptBody="true" />
<fault signatureOptions="IncludeAddressing, IncludeTimestamp,
IncludeSoapBody" encryptBody="false" />
</protection>
</usernameForCertificateSecurity>
<requireActionHeader />
</policy>
</policies>

As I mentioned, this works when I use the windows client to access the
web service, but when I try to access the web service using NUnit, I
get the following exception :

System.ArgumentOutOfRangeException occurred
Message="Specified argument was out of the range of valid values.\r
\nParameter name: Policy 'ClientPolicy' is not configured in the
system"
Source="Microsoft.Web.Services3"
ParamName="Policy 'ClientPolicy' is not configured in the system"

This seems to imply that the system can't find or load the appropriate
config file. But I fail to see why. Both the files are present in the
project directory. I've also copied both the config files to the
directory where the Nunit project file (and the dlls being tested) are
present. I've also tried copying it to the directory where the
NUnit.exe itself is located, but it doesn't make any difference. I've
added references to both "Microsoft.Web.Services3" and
"System.Configuration" modules in both my projects (windows client,
NUnit test class).

Any help regarding this would be much appreciated. Is there something
I am doing wrong/missing here or is this an inherent problem with
NUnit?

Thanks in advance.
 
N

nyathancha

Anyone? Any wse experts out there?

Hi,
I am using WSE to implement security using x509 certificates. This
works when I use a windows client but throws an exception when I use
NUnit.

My Code looks as follows :
UsernameToken myCurrentToken = new UsernameToken("xxxx", "YYY",
PasswordOption.SendPlainText);
MyServicesWse adminServices = new MyServicesWse();

adminServices.SetClientCredential<UsernameToken>(myCurrentToken);
adminServices.SetPolicy("ClientPolicy");

The App.Config has

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="microsoft.web.services3"
type="Microsoft.Web.Services3.Configuration.WebServicesConfiguration,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="{ModuleNamespace}.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
<section name="{ModuleNamespace}.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</sectionGroup>
</configSections>

<microsoft.web.services3>
<security>
<x509 allowTestRoot="true" storeLocation="CurrentUser" />
</security>
<tokenIssuer>
<statefulSecurityContextToken enabled="true" />
</tokenIssuer>
<messaging>
<mtom clientMode="On" />
</messaging>
<policy fileName="wse3policyCache.config" />
</microsoft.web.services3>

<applicationSettings>
... [Web Reference]
</applicationSettings>
</configuration>

and the wse3policyCache.config file has

<policies xmlns="http://schemas.microsoft.com/wse/2005/06/policy">
<extensions>
<extension name="usernameForCertificateSecurity"
type="Microsoft.Web.Services3.Design.UsernameForCertificateAssertion,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
<extension name="x509"
type="Microsoft.Web.Services3.Design.X509TokenProvider,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
<extension name="requireActionHeader"
type="Microsoft.Web.Services3.Design.RequireActionHeaderAssertion,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
</extensions>
<policy name="ClientPolicy">
<usernameForCertificateSecurity establishSecurityContext="true"
renewExpiredSecurityContext="true"
requireSignatureConfirmation="false"
messageProtectionOrder="SignBeforeEncrypt" requireDerivedKeys="true"
ttlInSeconds="300">
<serviceToken>
<x509 storeLocation="CurrentUser" storeName="AddressBook"
findValue="CN=WSE2QuickStartServer"
findType="FindBySubjectDistinguishedName" />
</serviceToken>
<protection>
<request signatureOptions="IncludeAddressing,
IncludeTimestamp, IncludeSoapBody" encryptBody="true" />
<response signatureOptions="IncludeAddressing,
IncludeTimestamp, IncludeSoapBody" encryptBody="true" />
<fault signatureOptions="IncludeAddressing, IncludeTimestamp,
IncludeSoapBody" encryptBody="false" />
</protection>
</usernameForCertificateSecurity>
<requireActionHeader />
</policy>
</policies>

As I mentioned, this works when I use the windows client to access the
web service, but when I try to access the web service using NUnit, I
get the following exception :

System.ArgumentOutOfRangeException occurred
Message="Specified argument was out of the range of valid values.\r
\nParameter name: Policy 'ClientPolicy' is not configured in the
system"
Source="Microsoft.Web.Services3"
ParamName="Policy 'ClientPolicy' is not configured in the system"

This seems to imply that the system can't find or load the appropriate
config file. But I fail to see why. Both the files are present in the
project directory. I've also copied both the config files to the
directory where the Nunit project file (and the dlls being tested) are
present. I've also tried copying it to the directory where the
NUnit.exe itself is located, but it doesn't make any difference. I've
added references to both "Microsoft.Web.Services3" and
"System.Configuration" modules in both my projects (windows client,
NUnit test class).

Any help regarding this would be much appreciated. Is there something
I am doing wrong/missing here or is this an inherent problem with
NUnit?

Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top