By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,684 Members | 1,439 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,684 IT Pros & Developers. It's quick & easy.

SetPolicy Exception while using NUnit

P: n/a
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>(m yCurrentToken);
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.WebSer vicesConfiguration,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, 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.UsernameForCe rtificateAssertion,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
<extension name="x509"
type="Microsoft.Web.Services3.Design.X509TokenProv ider,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
<extension name="requireActionHeader"
type="Microsoft.Web.Services3.Design.RequireAction HeaderAssertion,
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.

Jun 12 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Anyone? Any wse experts out there?

On Jun 12, 3:32 pm, nyathan...@hotmail.com wrote:
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>(m yCurrentToken);
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.WebSer vicesConfiguration,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, 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.UsernameForCe rtificateAssertion,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
<extension name="x509"
type="Microsoft.Web.Services3.Design.X509TokenProv ider,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
<extension name="requireActionHeader"
type="Microsoft.Web.Services3.Design.RequireAction HeaderAssertion,
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.

Jun 14 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.