Hi,
I was trying to assign a code-based policy to the service.
It works fine.
But if I add following line, the service gets failed.
assertion.EstablishSecurityContext = true;
Please suggest.
My Service policy is as follows
public MyPolicy()
{
// use a turnkey assertion to get us started
UsernameForCertificateAssertion assertion =
new UsernameForCertificateAssertion();
// select the server's X509 certificate
assertion.X509TokenProvider =
new X509TokenProvider(StoreLocation.LocalMachine,
StoreName.My,
"CN=WSE2QuickStartServer",
X509FindType.FindBySubjectDistinguishedName);
EndpointProtectionRequirements epr = assertion.Protection;
// require signature and encryption for incoming requests
epr.Request.SignatureOptions =
SignatureOptions.IncludeAddressing |
SignatureOptions.IncludeTimestamp |
SignatureOptions.IncludeSoapBody;
epr.Request.EncryptBody = true;
// include signature and encryption for outgoing response
epr.Response.SignatureOptions =
SignatureOptions.IncludeAddressing |
SignatureOptions.IncludeTimestamp |
SignatureOptions.IncludeSoapBody;
epr.Response.EncryptBody = true;
// don't encrypt faults, just sign
epr.Fault.SignatureOptions =
SignatureOptions.IncludeAddressing |
SignatureOptions.IncludeTimestamp |
SignatureOptions.IncludeSoapBody;
epr.Fault.EncryptBody = false;
assertion.MessageProtectionOrder =
MessageProtectionOrder.SignBeforeEncrypt;
assertion.RequireDerivedKeys = true;
/* The below statement raise a error. */
assertion.EstablishSecurityContext = true;
this.Assertions.Add(assertion);
}
Error details -
{Microsoft.Web.Services3.ResponseProcessingException: 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. ---> System.InvalidOperationException: Security
requirements are not satisfied because the security header is not present in
the incoming message.
at
Microsoft.Web.Services3.Security.SecureConversationClientReceiveSecurityFilter.ValidateMessageSecurity(SoapEnvelope envelope, Security security)
at
Microsoft.Web.Services3.Security.ReceiveSecurityFilter.ProcessMessage(SoapEnvelope envelope)
at Microsoft.Web.Services3.Pipeline.ProcessInputMessage(SoapEnvelope
envelope)
at
Microsoft.Web.Services3.Xml.SoapEnvelopeReaderWrapper..ctor(SoapClientMessage
message, String messageContentType)
--- End of inner exception stack trace ---
at
Microsoft.Web.Services3.Xml.SoapEnvelopeReaderWrapper..ctor(SoapClientMessage
message, String messageContentType)
at
Microsoft.Web.Services3.WebServicesClientProtocol.GetReaderForMessage(SoapClientMessage message, Int32 bufferSize)
at
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String
methodName, Object[] parameters)
at services.SecureInvoiceServiceWse.ViewInvoices() in
C:\Pravin\Projects\WSE\3.0\Hands On Lab -
Security\CS\Advanced\Part1\after\SecureInvoiceClient\Web
References\services\Reference.cs:line 94
at SecureInvoiceClient.InvoiceManagerForm.ViewInvoices() in
C:\Pravin\Projects\WSE\3.0\Hands On Lab -
Security\CS\Advanced\Part1\after\SecureInvoiceClient\InvoiceManagerForm.cs:line 158
at SecureInvoiceClient.InvoiceManagerForm.btnView_Click(Object sender,
EventArgs e) in C:\Pravin\Projects\WSE\3.0\Hands On Lab -
Security\CS\Advanced\Part1\after\SecureInvoiceClient\InvoiceManagerForm.cs:line 186}

Signature
------------------------
Pravin Patil
Pablo Cibraro - 16 Nov 2005 13:30 GMT
Hi Pravin,
Have you set the "EstablishSecurityContext" to true in the service policy ?.
(That attribute must have the same value in both endpoints)
Regards,
Pablo Cibraro
http://weblogs.asp.net/cibrax
http://www.lagash.com
> Hi,
>
[quoted text clipped - 97 lines]
> Security\CS\Advanced\Part1\after\SecureInvoiceClient\InvoiceManagerForm.cs:line
> 186}
Pravin Patil - 16 Nov 2005 14:56 GMT
Yes, I did that. Still the problem has not been resolved. :-(
------------------------
Pravin Patil
> Hi Pravin,
> Have you set the "EstablishSecurityContext" to true in the service policy ?.
[quoted text clipped - 106 lines]
> > Security\CS\Advanced\Part1\after\SecureInvoiceClient\InvoiceManagerForm.cs:line
> > 186}
Pablo Cibraro - 17 Nov 2005 14:43 GMT
The error "System.InvalidOperationException: Security requirements are not
satisfied because the security header is not present." happens when the soap
envelope for the request doesn't contain the security header.
For some reason, WSE is not adding that header in the client. Are you
applying that policy to the service proxy ?
Regards,
Pablo Cibraro
http://weblogs.asp.net/cibrax
http://www.lagash.com
> Yes, I did that. Still the problem has not been resolved. :-(
>
[quoted text clipped - 117 lines]
>> > Security\CS\Advanced\Part1\after\SecureInvoiceClient\InvoiceManagerForm.cs:line
>> > 186}
Pravin Patil - 17 Nov 2005 15:41 GMT
Yes, Pablo,
I do apply this Policy to Service as written below.
[Policy(typeof(MyPolicy))]
public class SecureInvoiceService : System.Web.Services.WebService
{
}
Thanks for the quick response.
------------------------
Pravin Patil
> The error "System.InvalidOperationException: Security requirements are not
> satisfied because the security header is not present." happens when the soap
[quoted text clipped - 128 lines]
> >> > Security\CS\Advanced\Part1\after\SecureInvoiceClient\InvoiceManagerForm.cs:line
> >> > 186}
Pablo Cibraro - 18 Nov 2005 14:08 GMT
Hi Pravin,
That is the web service. Have you applied the same policy to service proxy
?.
Regards,
Pablo Cibraro
http://weblogs.asp.net/cibrax
http://www.lagash.com
> Yes, Pablo,
>
[quoted text clipped - 149 lines]
>> >> > Security\CS\Advanced\Part1\after\SecureInvoiceClient\InvoiceManagerForm.cs:line
>> >> > 186}
Pravin Patil - 18 Nov 2005 17:00 GMT
Yes, I have written a user defined policy assertion for Client app. And
assigned that assertion policy to Service proxy in the client app.
Policy Code:-
public class UsernameClientAssertion : SecurityPolicyAssertion
{
UserCredentials userCredentials;
public UsernameClientAssertion(UserCredentials userCredentials)
{
this.userCredentials = userCredentials;
...
this.RequireSignatureConfirmation = true;
this.RequireDerivedKeys = true;
this.EstablishSecurityContext = true;
this.RenewExpiredSecurityContext = true;
this.ClientActor = "";
}
#region ClientOutputFilter
class ClientOutputFilter : SendSecurityFilter
{
UsernameClientAssertion parentAssertion;
FilterCreationContext filterContext;
public ClientOutputFilter(UsernameClientAssertion
parentAssertion, FilterCreationContext filterContext)
: base(parentAssertion.ServiceActor, false,
parentAssertion.ClientActor)
{
this.parentAssertion = parentAssertion;
this.filterContext = filterContext;
}
public override void SecureMessage(SoapEnvelope envelope,
Security security)
{
UsernameToken userToken = new UsernameToken(
parentAssertion.userCredentials.UserName,
parentAssertion.userCredentials.Password,
PasswordOption.SendNone); // we don't send password over
network
// but we just use username/password to sign/encrypt message
// Add the token to the SOAP header.
security.Tokens.Add(userToken);
// encrypt BODY
EncryptedData data = new EncryptedData(userToken);
// encrypt custom headers
// add ancrypted data to the security context
security.Elements.Add(data);
}
}
#endregion
}
Code :-
UsernameClientAssertion assert = new
UsernameClientAssertion(this.userCredentials);
Policy policy = new Policy();
policy.Assertions.Add(assert);
service.SetPolicy(policy);
------------------------
Pravin Patil
> Hi Pravin,
> That is the web service. Have you applied the same policy to service proxy
[quoted text clipped - 158 lines]
> >> >> > Security\CS\Advanced\Part1\after\SecureInvoiceClient\InvoiceManagerForm.cs:line
> >> >> > 186}