Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody.

I've just register to The Code Project, but its been a while since I follow threads in here, and I want to congrat all the community that makes this page as it good as it is.

Well to the question now.

I'm trying to set security in a webservice using WSE 3.0 (I know, I know, It's deprecated...but its the technology I have to use)
The security I need is a certificate sign & encrypt security (No password, just mutual certificate)
I've started with the example in WSE samples, but I run into the following problems.

public class TheClient {

    private readonly WebServiceWse webService;

    public TheClient() {
        webService = new WebServiceWse();
        // webService.SetPolicy("MyCustomPolicy");

if I unncoment the commented line, It rasises the following error.

Specified argument was out of the range of valid values.
Parameter name: Policy 'MyCustomPolicy' is not configured in the system

although I have it in my policy file, wich is referenced by the app.config.

If I leave the line commented, then it raises

Server unavailable. Try again later

but the server is up and running, and I can access the webservice through browser.

By the way.
The solution consists of 3 projects

The WebServer
The Client
A Test Windows Form Application

The one that starts is the Windows Form application, and that one, uses the client to access the webserver.
For what it seams, the problem is that the Client does not load its app config, but the WinForms app.config is the one that loads.

Maybe the solution is simple, but as Im new to C# and Visual Studio, I cant find out any.

If any one can give me a hint I would really appreciat it.

Thanks in advance
Updated 10-Jan-11 3:22am

Try something like this:
Mapping Certificates to User Accounts[^]

Some more usefull info here
IIS Authentication[^]

Hopefully this helps ...

Espen Harlinn
Share this answer
Dalek Dave 10-Jan-11 9:49am    
Good Links.
Espen Harlinn 10-Jan-11 9:53am    
Thanks Dalek!
Find out that the problem was the following

My solution structure is as follwoing:

+-- WebService (ASP webservice)
+-- Client (Class Library)
+-- TestUI (WinForms Application)

The WSE 3.0 Configuration were in the WebService web.config and policy.config (referenced by web.config) files (For the server)
And in app.config and policy.config (referenced by the app.config) in Client (For the client)

The policy.config for the Client had a policy section as follows

<policy name="ClientPolicy">
  <mutualCertificate11Security establishSecurityContext="true" renewExpiredSecurityContext="true" requireSignatureConfirmation="true" messageProtectionOrder="SignBeforeEncrypt" requireDerivedKeys="true" ttlInSeconds="300">
      <x509 storeLocation="LocalMachine" storeName="My" findValue="CN=CertificateForClient" findType="FindBySubjectDistinguishedName" />
      <x509 storeLocation="LocalMachine" storeName="AddressBook" findValue="CN=CertificateForServer" findType="FindBySubjectDistinguishedName" />
      <request signatureOptions="IncludeAddressing, IncludeTimestamp, IncludeSoapBody" encryptBody="true" />
      <response signatureOptions="IncludeAddressing, IncludeTimestamp, IncludeSoapBody" encryptBody="true" />
      <fault signatureOptions="IncludeAddressing, IncludeTimestamp, IncludeSoapBody" encryptBody="false" />
  <requireActionHeader />

The problem was that, as the start project was TestUI, the app.config that loads is the one on that project, and not the one in the Client project, thus, not loading the policy.config in Client project.
That makes that the following line in the client fails


with the ArgumentOutOfRangeException.

So...the solution I found...copy the policy file in the TestUI project and reference it from the app.config in that project.
Although I don't like that solution...IMHO they are different projects, and their configurations should be independient.
I'm guessing that there is a way to solve this, but I can't figure out how. If someone knows how, plase tell.

So...that solved the problem. Now I'm having a WSE error in which states:

WSE910: An error happened during the processing of a response message,
and you can find the error in the inner exception. You can also find
the response message in the Response property.

and the inner exception states:

Security requirements are not satisfied because the security header is
not present in the incoming message.

I'm guessing certificate problems. I barely could take a look at your answer Espen, but for what I see, it may help me to solve this new problem that appears. So thanks a lot for your answer.

Hope this helps to anybody that runs into the same situation that I did.

Share this answer
Hey,I have the same issue.what is your solution thanks.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900