1 //------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //------------------------------------------------------------
5 namespace System.ServiceModel.Security
8 using System.Collections;
9 using System.Collections.Generic;
10 using System.Diagnostics;
11 using System.IdentityModel;
12 using System.IdentityModel.Configuration;
13 using System.IdentityModel.Diagnostics;
14 using System.IdentityModel.Protocols.WSTrust;
15 using System.IdentityModel.Selectors;
16 using System.IdentityModel.Tokens;
18 using System.Security.Claims;
19 using System.ServiceModel;
20 using System.ServiceModel.Activation;
21 using System.ServiceModel.Channels;
22 using System.ServiceModel.Description;
23 using System.Threading;
24 using System.Web.Services.Description;
26 using System.Xml.Schema;
27 using DiagnosticUtility = System.IdentityModel.DiagnosticUtility;
28 using Message = System.ServiceModel.Channels.Message;
29 using RequestContext = System.ServiceModel.Channels.RequestContext;
30 using RST = System.IdentityModel.Protocols.WSTrust.RequestSecurityToken;
31 using RSTR = System.IdentityModel.Protocols.WSTrust.RequestSecurityTokenResponse;
32 using SR = System.ServiceModel.SR;
33 using STS = System.IdentityModel.SecurityTokenService;
34 using Fx = System.Runtime.Fx;
37 /// Definition of Trust Contract Implementation. Implements the following ServiceContract interfaces,
38 /// 1. IWSTrustFeb2005SyncContract
39 /// 2. IWSTrust13SyncContract
40 /// 3. IWSTrustFeb2005AsyncContract
41 /// 4. IWSTrust13AsyncContract
43 [ServiceBehavior(Name = WSTrustServiceContractConstants.ServiceBehaviorName, Namespace = WSTrustServiceContractConstants.Namespace, InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
44 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
45 public class WSTrustServiceContract : IWSTrustFeb2005SyncContract, IWSTrust13SyncContract, IWSTrustFeb2005AsyncContract, IWSTrust13AsyncContract, IWsdlExportExtension, IContractBehavior
47 const string soap11Namespace = "http://schemas.xmlsoap.org/soap/envelope/";
48 const string soap12Namespace = "http://www.w3.org/2003/05/soap-envelope";
50 SecurityTokenServiceConfiguration _securityTokenServiceConfiguration;
52 event EventHandler<WSTrustRequestProcessingErrorEventArgs> _requestFailed;
55 /// Initializes an instance of <see cref="WSTrustServiceContract"/>
57 /// <param name="securityTokenServiceConfiguration">Configuration object that initializes this instance.</param>
58 public WSTrustServiceContract(SecurityTokenServiceConfiguration securityTokenServiceConfiguration)
60 if (securityTokenServiceConfiguration == null)
62 throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("securityTokenServiceConfiguration");
65 _securityTokenServiceConfiguration = securityTokenServiceConfiguration;
69 /// Occurs when a Failure happens processing a Trust request from the
72 public event EventHandler<WSTrustRequestProcessingErrorEventArgs> RequestFailed
74 add { _requestFailed += value; }
75 remove { _requestFailed -= value; }
79 /// Returns the <see cref="SecurityTokenResolver" /> that resolves the following security tokens contained
80 /// in the current WCF message request's security header: protection token, endorsing, or signed endorsing
81 /// supporting tokens.
84 /// This <see cref="SecurityTokenResolver" /> is used to resolve any SecurityTokenIdentifiers
85 /// when deserializing RST UseKey elements or RST RenewTarget elements.
87 /// <exception cref="ArgumentNullException"><param name="requestContext"/> is null.</exception>
88 protected virtual SecurityTokenResolver GetSecurityHeaderTokenResolver(RequestContext requestContext)
90 if (requestContext == null)
92 throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("requestContext");
95 List<SecurityToken> tokenList = new List<SecurityToken>();
96 if (requestContext.RequestMessage != null
97 && requestContext.RequestMessage.Properties != null
98 && requestContext.RequestMessage.Properties.Security != null)
100 // Add tokens in message
101 SecurityMessageProperty msgProperty = requestContext.RequestMessage.Properties.Security;
102 if (msgProperty.ProtectionToken != null)
104 tokenList.Add(msgProperty.ProtectionToken.SecurityToken);
106 if (msgProperty.HasIncomingSupportingTokens)
108 foreach (SupportingTokenSpecification tokenSpec in msgProperty.IncomingSupportingTokens)
110 if (tokenSpec != null &&
111 (tokenSpec.SecurityTokenAttachmentMode == SecurityTokenAttachmentMode.Endorsing ||
112 tokenSpec.SecurityTokenAttachmentMode == SecurityTokenAttachmentMode.SignedEndorsing))
114 tokenList.Add(tokenSpec.SecurityToken);
119 if (msgProperty.InitiatorToken != null)
121 tokenList.Add(msgProperty.InitiatorToken.SecurityToken);
125 if (tokenList.Count > 0)
127 return SecurityTokenResolver.CreateDefaultSecurityTokenResolver(tokenList.AsReadOnly(), true);
131 return EmptySecurityTokenResolver.Instance;
136 /// Returns the <see cref="SecurityTokenResolver" /> that will be used when resolving tokens and keys in the
137 /// Trust message body.
139 /// <returns>A <see cref="SecurityTokenResolver" /> instance.</returns>
140 /// <seealso cref="GetSecurityHeaderTokenResolver"/>
141 protected virtual SecurityTokenResolver GetRstSecurityTokenResolver()
143 if (_securityTokenServiceConfiguration != null)
145 SecurityTokenResolver tokenResolver = _securityTokenServiceConfiguration.SecurityTokenHandlers.Configuration.ServiceTokenResolver;
147 if (tokenResolver != null && (!Object.ReferenceEquals(tokenResolver, EmptySecurityTokenResolver.Instance)))
149 return tokenResolver;
153 if (OperationContext.Current != null && OperationContext.Current.Host != null &&
154 OperationContext.Current.Host.Description != null)
156 ServiceCredentials serviceCreds = OperationContext.Current.Host.Description.Behaviors.Find<ServiceCredentials>();
157 if (serviceCreds != null && serviceCreds.ServiceCertificate != null && serviceCreds.ServiceCertificate.Certificate != null)
159 List<SecurityToken> serviceTokens = new List<SecurityToken>(1);
160 serviceTokens.Add(new X509SecurityToken(serviceCreds.ServiceCertificate.Certificate));
161 return SecurityTokenResolver.CreateDefaultSecurityTokenResolver(serviceTokens.AsReadOnly(), false);
165 return EmptySecurityTokenResolver.Instance;
169 /// Creates a WSTrustSerializationContext using the local resolver information
170 /// of the WSTrustServiceClient.
172 /// <returns>A WSTrustSerializationContext initialized with the current resolver information.</returns>
173 protected virtual WSTrustSerializationContext CreateSerializationContext()
175 return new WSTrustSerializationContext(_securityTokenServiceConfiguration.SecurityTokenHandlerCollectionManager,
176 this.GetRstSecurityTokenResolver(),
177 this.GetSecurityHeaderTokenResolver(OperationContext.Current.RequestContext)
183 /// Begins an asynchronous call to <see cref="DispatchRequest"/>.
185 /// <param name="dispatchContext">Defines the request parameters to process and exposes properties
186 /// that determine the response message and action.</param>
187 /// <param name="asyncCallback">An optional asynchronous callback, to be called when the
188 /// dispatch is complete.</param>
189 /// <param name="asyncState">A user-provided object that distinguishes this particular asynchronous
190 /// dispatch request from other requests.</param>
191 /// <returns><see cref="IAsyncResult"/> that represents the asynchronous operation. Used as the input
192 /// to <see cref="EndDispatchRequest"/>.</returns>
193 protected virtual IAsyncResult BeginDispatchRequest(DispatchContext dispatchContext, AsyncCallback asyncCallback, object asyncState)
195 return new DispatchRequestAsyncResult(dispatchContext, asyncCallback, asyncState);
199 /// Completes an asynchronous call to <see cref="DispatchRequest"/>.
201 /// <param name="ar"><see cref="IAsyncResult"/> that was returned by the
202 /// call to <see cref="BeginDispatchRequest"/>.</param>
203 /// <returns>The <see cref="DispatchContext"/> that exposes properties which determine the response
204 /// message and action.</returns>
205 protected virtual DispatchContext EndDispatchRequest(IAsyncResult ar)
207 return DispatchRequestAsyncResult.End(ar);
211 /// Processes a WS-Trust request message, and optionally determines the appropriate
212 /// response message and the WS-Addressing action for the response message.
214 /// <param name="dispatchContext">Defines the request parameters to process and exposes properties
215 /// that determine the response message and action.</param>
216 protected virtual void DispatchRequest(DispatchContext dispatchContext)
218 RST rst = dispatchContext.RequestMessage as RST;
219 STS sts = dispatchContext.SecurityTokenService;
220 ClaimsPrincipal icp = dispatchContext.Principal;
224 switch (rst.RequestType)
226 case RequestTypes.Cancel:
227 dispatchContext.ResponseMessage = sts.Cancel(icp, rst);
229 case RequestTypes.Issue:
230 dispatchContext.ResponseMessage = sts.Issue(icp, rst);
232 case RequestTypes.Renew:
233 dispatchContext.ResponseMessage = sts.Renew(icp, rst);
235 case RequestTypes.Validate:
236 dispatchContext.ResponseMessage = sts.Validate(icp, rst);
239 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ID3112, rst.RequestType)));
244 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidRequestException(SR.GetString(SR.ID3022)));
249 /// Handles Synchronous calls to the STS.
251 /// <param name="requestMessage">Incoming Request message.</param>
252 /// <param name="requestSerializer">Trust Request Serializer.</param>
253 /// <param name="responseSerializer">Trust Response Serializer.</param>
254 /// <param name="requestAction">Request SOAP action.</param>
255 /// <param name="responseAction">Response SOAP action.</param>
256 /// <param name="trustNamespace">Namespace URI of the trust version of the incoming request.</param>
257 /// <returns>Response message that contains the serialized RSTR.</returns>
258 /// <exception cref="ArgumentNullException">One of the argument is null.</exception>
259 protected virtual Message ProcessCore(Message requestMessage, WSTrustRequestSerializer requestSerializer, WSTrustResponseSerializer responseSerializer, string requestAction, string responseAction, string trustNamespace)
261 if (requestMessage == null)
263 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("requestMessage");
266 if (requestSerializer == null)
268 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("requestSerializer");
271 if (responseSerializer == null)
273 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("responseSerializer");
276 if (String.IsNullOrEmpty(requestAction))
278 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("requestAction");
281 if (String.IsNullOrEmpty(responseAction))
283 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("responseAction");
286 if (String.IsNullOrEmpty(trustNamespace))
288 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("trustNamespace");
291 Message response = null;
294 Fx.Assert(OperationContext.Current != null, "");
295 Fx.Assert(OperationContext.Current.RequestContext != null, "");
298 // Create the Serialization and Dispatch context objects.
300 WSTrustSerializationContext serializationContext = CreateSerializationContext();
302 DispatchContext dispatchContext = CreateDispatchContext(requestMessage,
308 serializationContext);
311 // Validate the dispatch context.
313 ValidateDispatchContext(dispatchContext);
316 // Dispatch the STS message.
318 DispatchRequest(dispatchContext);
321 // Create the response Message object with the appropriate action.
323 response = Message.CreateMessage(OperationContext.Current.RequestContext.RequestMessage.Version,
324 dispatchContext.ResponseAction,
325 new WSTrustResponseBodyWriter(dispatchContext.ResponseMessage, responseSerializer, serializationContext));
329 if (!HandleException(ex, trustNamespace, requestAction, requestMessage.Version.Envelope))
339 /// Creates a <see cref="DispatchContext"/> object for use by the <see cref="DispatchRequest"/> method.
341 /// <param name="requestMessage">The incoming request message.</param>
342 /// <param name="requestAction">The SOAP action of the request.</param>
343 /// <param name="responseAction">The default SOAP action of the response.</param>
344 /// <param name="trustNamespace">Namespace URI of the trust version of the incoming request.</param>
345 /// <param name="requestSerializer">The <see cref="WSTrustRequestSerializer"/> used to deserialize
346 /// incoming RST messages.</param>
347 /// <param name="responseSerializer">The <see cref="WSTrustResponseSerializer"/> used to deserialize
348 /// incoming RSTR messages.</param>
349 /// <param name="serializationContext">The <see cref="WSTrustSerializationContext"/> to use
350 /// when deserializing incoming messages.</param>
351 /// <returns>A <see cref="DispatchContext"/> object.</returns>
352 protected virtual DispatchContext CreateDispatchContext(Message requestMessage,
353 string requestAction,
354 string responseAction,
355 string trustNamespace,
356 WSTrustRequestSerializer requestSerializer,
357 WSTrustResponseSerializer responseSerializer,
358 WSTrustSerializationContext serializationContext)
360 DispatchContext dispatchContext = new DispatchContext()
362 Principal = OperationContext.Current.ClaimsPrincipal as ClaimsPrincipal,
363 RequestAction = requestAction,
364 ResponseAction = responseAction,
365 TrustNamespace = trustNamespace
368 XmlReader requestBodyReader = requestMessage.GetReaderAtBodyContents();
370 // Take a peek at the request with the serializers to figure out if this is a standard incoming
371 // RST or if this is an instance of a challenge-response style message pattern where an RSTR comes in.
373 if (requestSerializer.CanRead(requestBodyReader))
375 dispatchContext.RequestMessage = requestSerializer.ReadXml(requestBodyReader, serializationContext);
377 else if (responseSerializer.CanRead(requestBodyReader))
379 dispatchContext.RequestMessage = responseSerializer.ReadXml(requestBodyReader, serializationContext);
383 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
384 new InvalidRequestException(SR.GetString(SR.ID3114)));
388 // CAUTION: Don't create the STS until after the RST or RSTR is deserialized or the test team
389 // has major infrastructure problems.
391 dispatchContext.SecurityTokenService = CreateSTS();
392 return dispatchContext;
396 /// Validates the DispatchContext.
398 /// <param name="dispatchContext">The <see cref="DispatchContext"/> to validate.</param>
400 /// This routine ensures that the <see cref="DispatchContext"/> represents a legal request
401 /// prior to being passed into <see cref="DispatchRequest"/>. This routine's default implementation
402 /// is to reject incoming RST messages with RSTR actions and vice versa.
404 protected virtual void ValidateDispatchContext(DispatchContext dispatchContext)
406 if (dispatchContext.RequestMessage is RST
407 && !IsValidRSTAction(dispatchContext))
409 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
410 new InvalidRequestException(
411 SR.GetString(SR.ID3113, "RequestSecurityToken", dispatchContext.RequestAction)));
414 if (dispatchContext.RequestMessage is RSTR
415 && !IsValidRSTRAction(dispatchContext))
417 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
418 new InvalidRequestException(
419 SR.GetString(SR.ID3113, "RequestSecurityTokenResponse", dispatchContext.RequestAction)));
424 /// Determines if the DispatchContext contains a valid request action for incoming RST messages.
426 private static bool IsValidRSTAction(DispatchContext dispatchContext)
429 string action = dispatchContext.RequestAction;
431 if (dispatchContext.TrustNamespace == WSTrust13Constants.NamespaceURI)
435 case WSTrust13Constants.Actions.Cancel:
436 case WSTrust13Constants.Actions.Issue:
437 case WSTrust13Constants.Actions.Renew:
438 case WSTrust13Constants.Actions.Validate:
443 if (dispatchContext.TrustNamespace == WSTrustFeb2005Constants.NamespaceURI)
447 case WSTrustFeb2005Constants.Actions.Cancel:
448 case WSTrustFeb2005Constants.Actions.Issue:
449 case WSTrustFeb2005Constants.Actions.Renew:
450 case WSTrustFeb2005Constants.Actions.Validate:
460 /// Determines if the DispatchContext contains a valid request action for incoming RSTR messages.
462 private static bool IsValidRSTRAction(DispatchContext dispatchContext)
465 string action = dispatchContext.RequestAction;
467 if (dispatchContext.TrustNamespace == WSTrust13Constants.NamespaceURI)
471 case WSTrust13Constants.Actions.CancelFinalResponse:
472 case WSTrust13Constants.Actions.CancelResponse:
473 case WSTrust13Constants.Actions.IssueFinalResponse:
474 case WSTrust13Constants.Actions.IssueResponse:
475 case WSTrust13Constants.Actions.RenewFinalResponse:
476 case WSTrust13Constants.Actions.RenewResponse:
477 case WSTrust13Constants.Actions.ValidateFinalResponse:
478 case WSTrust13Constants.Actions.ValidateResponse:
483 if (dispatchContext.TrustNamespace == WSTrustFeb2005Constants.NamespaceURI)
487 case WSTrustFeb2005Constants.Actions.CancelResponse:
488 case WSTrustFeb2005Constants.Actions.IssueResponse:
489 case WSTrustFeb2005Constants.Actions.RenewResponse:
490 case WSTrustFeb2005Constants.Actions.ValidateResponse:
499 private STS CreateSTS()
501 STS sts = _securityTokenServiceConfiguration.CreateSecurityTokenService();
505 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ID3002)));
512 /// Handles Asynchronous call to the STS.
514 /// <param name="requestMessage">Incoming Request message.</param>
515 /// <param name="requestSerializer">Trust Request Serializer.</param>
516 /// <param name="responseSerializer">Trust Response Serializer.</param>
517 /// <param name="requestAction">Request SOAP action.</param>
518 /// <param name="responseAction">Response SOAP action.</param>
519 /// <param name="trustNamespace">Namespace URI of the trust version of the incoming request.</param>
520 /// <param name="callback">Callback that gets invoked when the Asynchronous call ends.</param>
521 /// <param name="state">state information of the Asynchronous call.</param>
522 /// <returns>IAsyncResult that should be passed back to the End method to complete the Asynchronous call.</returns>
523 /// <exception cref="ArgumentNullException">One of the argument is null.</exception>
524 protected virtual IAsyncResult BeginProcessCore(Message requestMessage, WSTrustRequestSerializer requestSerializer, WSTrustResponseSerializer responseSerializer, string requestAction, string responseAction, string trustNamespace, AsyncCallback callback, object state)
526 if (requestMessage == null)
528 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("request");
531 if (requestSerializer == null)
533 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("requestSerializer");
536 if (responseSerializer == null)
538 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("responseSerializer");
541 if (String.IsNullOrEmpty(requestAction))
543 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("requestAction");
546 if (String.IsNullOrEmpty(responseAction))
548 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("responseAction");
551 if (String.IsNullOrEmpty(trustNamespace))
553 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("trustNamespace");
556 IAsyncResult result = null;
559 Fx.Assert(OperationContext.Current != null, "");
560 Fx.Assert(OperationContext.Current.RequestContext != null, "");
563 // Create the Serialization and Dispatch context objects.
565 WSTrustSerializationContext serializationContext = CreateSerializationContext();
567 DispatchContext dispatchContext = CreateDispatchContext(requestMessage,
573 serializationContext);
576 // Validate the dispatch context.
578 ValidateDispatchContext(dispatchContext);
581 // Dispatch the message asynchronously.
583 result = new ProcessCoreAsyncResult(this,
585 OperationContext.Current.RequestContext.RequestMessage.Version,
587 serializationContext,
593 if (!HandleException(ex, trustNamespace, requestAction, requestMessage.Version.Envelope))
603 /// Completes an Asynchronous call to the STS.
605 /// <param name="ar">IAsyncResult that was returned by the call to the Asynchronous Begin method.</param>
606 /// <param name="requestAction">Request SOAP Action.</param>
607 /// <param name="responseAction">Response SOAP Action.</param>
608 /// <param name="trustNamespace">Namespace URI of the current trust version.</param>
609 /// <returns>Message that contains the serialized RST message.</returns>
610 /// <exception cref="ArgumentNullException">One of the argument is null.</exception>
611 protected virtual Message EndProcessCore(IAsyncResult ar, string requestAction, string responseAction, string trustNamespace)
615 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("ar");
618 ProcessCoreAsyncResult asyncResult = ar as ProcessCoreAsyncResult;
619 if (asyncResult == null)
621 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.ID2004, typeof(ProcessCoreAsyncResult), ar.GetType()), "ar"));
624 Message message = null;
627 message = ProcessCoreAsyncResult.End(ar);
631 if (!HandleException(ex, trustNamespace, requestAction, asyncResult.MessageVersion.Envelope))
641 /// Raises the Error Event and converts the given exception to a FaultException if required. If the original
642 /// exception was a FaultException or PreserveOriginalException flag is set to true then the conversion to
643 /// FaultException is not done.
645 /// <param name="ex">The original exception.</param>
646 /// <param name="trustNamespace">Trust Namespace of the current trust version.</param>
647 /// <param name="action">The Trust action that caused the exception.</param>
648 /// <param name="requestEnvelopeVersion">Version of the request envolope.</param>
649 protected virtual bool HandleException(Exception ex, string trustNamespace, string action, EnvelopeVersion requestEnvelopeVersion)
651 if (System.Runtime.Fx.IsFatal(ex))
656 if (DiagnosticUtility.ShouldTrace(TraceEventType.Warning))
658 TraceUtility.TraceString(
659 TraceEventType.Warning,
660 "RequestFailed: TrustNamespace={0}, Action={1}, Exception={2}",
666 // raise the exception events.
667 if (_requestFailed != null)
669 _requestFailed(this, new WSTrustRequestProcessingErrorEventArgs(action, ex));
672 bool preserveOriginalException = false;
673 ServiceDebugBehavior debugBehavior = OperationContext.Current.Host.Description.Behaviors.Find<ServiceDebugBehavior>();
674 if (debugBehavior != null)
676 preserveOriginalException = debugBehavior.IncludeExceptionDetailInFaults;
679 if (String.IsNullOrEmpty(trustNamespace) || String.IsNullOrEmpty(action) || preserveOriginalException || ex is FaultException)
681 // Just throw the original exception.
686 FaultException faultException = OperationContext.Current.Host.Credentials.ExceptionMapper.FromException(ex, (requestEnvelopeVersion == EnvelopeVersion.Soap11) ? soap11Namespace : soap12Namespace, trustNamespace);
687 if (faultException != null)
689 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(faultException);
692 // The exception is not one of the recognized exceptions. Just throw the original exception.
697 #region IWSTrustFeb2005SyncContract and IWSTrust13SyncContract Methods
700 /// Processes a Trust 1.3 Cancel message synchronously.
702 /// <param name="message">Incoming Request message.</param>
703 /// <returns>Message with the serialized response.</returns>
704 public Message ProcessTrust13Cancel(Message message)
706 return ProcessCore(message, _securityTokenServiceConfiguration.WSTrust13RequestSerializer, _securityTokenServiceConfiguration.WSTrust13ResponseSerializer, WSTrust13Constants.Actions.Cancel, WSTrust13Constants.Actions.CancelFinalResponse, WSTrust13Constants.NamespaceURI);
710 /// Processes a Trust 1.3 Issue message synchronously.
712 /// <param name="message">Incoming Request message.</param>
713 /// <returns>Message with the serialized response.</returns>
714 public Message ProcessTrust13Issue(Message message)
716 return ProcessCore(message, _securityTokenServiceConfiguration.WSTrust13RequestSerializer, _securityTokenServiceConfiguration.WSTrust13ResponseSerializer, WSTrust13Constants.Actions.Issue, WSTrust13Constants.Actions.IssueFinalResponse, WSTrust13Constants.NamespaceURI);
720 /// Processes a Trust 1.3 Renew message synchronously.
722 /// <param name="message">Incoming Request message.</param>
723 /// <returns>Message with the serialized response.</returns>
724 public Message ProcessTrust13Renew(Message message)
726 return ProcessCore(message, _securityTokenServiceConfiguration.WSTrust13RequestSerializer, _securityTokenServiceConfiguration.WSTrust13ResponseSerializer, WSTrust13Constants.Actions.Renew, WSTrust13Constants.Actions.RenewFinalResponse, WSTrust13Constants.NamespaceURI);
730 /// Processes a Trust 1.3 Validate message synchronously.
732 /// <param name="message">Incoming Request message.</param>
733 /// <returns>Message with the serialized response.</returns>
734 public Message ProcessTrust13Validate(Message message)
736 return ProcessCore(message, _securityTokenServiceConfiguration.WSTrust13RequestSerializer, _securityTokenServiceConfiguration.WSTrust13ResponseSerializer, WSTrust13Constants.Actions.Validate, WSTrust13Constants.Actions.ValidateFinalResponse, WSTrust13Constants.NamespaceURI);
740 /// Processes a Trust 1.3 RSTR/Cancel message synchronously.
742 /// <param name="message">Incoming Request message.</param>
743 /// <returns>Message with the serialized response.</returns>
744 public Message ProcessTrust13CancelResponse(Message message)
746 return ProcessCore(message,
747 _securityTokenServiceConfiguration.WSTrust13RequestSerializer,
748 _securityTokenServiceConfiguration.WSTrust13ResponseSerializer,
749 WSTrust13Constants.Actions.CancelResponse,
750 WSTrust13Constants.Actions.CancelFinalResponse,
751 WSTrust13Constants.NamespaceURI);
755 /// Processes a Trust 1.3 RSTR/Issue message synchronously.
757 /// <param name="message">Incoming Request message.</param>
758 /// <returns>Message with the serialized response.</returns>
759 public Message ProcessTrust13IssueResponse(Message message)
761 return ProcessCore(message,
762 _securityTokenServiceConfiguration.WSTrust13RequestSerializer,
763 _securityTokenServiceConfiguration.WSTrust13ResponseSerializer,
764 WSTrust13Constants.Actions.IssueResponse,
765 WSTrust13Constants.Actions.IssueFinalResponse,
766 WSTrust13Constants.NamespaceURI);
770 /// Processes a Trust 1.3 RSTR/Renew message synchronously.
772 /// <param name="message">Incoming Request message.</param>
773 /// <returns>Message with the serialized response.</returns>
774 public Message ProcessTrust13RenewResponse(Message message)
776 return ProcessCore(message,
777 _securityTokenServiceConfiguration.WSTrust13RequestSerializer,
778 _securityTokenServiceConfiguration.WSTrust13ResponseSerializer,
779 WSTrust13Constants.Actions.RenewResponse,
780 WSTrust13Constants.Actions.RenewFinalResponse,
781 WSTrust13Constants.NamespaceURI);
785 /// Processes a Trust 1.3 RSTR/Validate message synchronously.
787 /// <param name="message">Incoming Request message.</param>
788 /// <returns>Message with the serialized response.</returns>
789 public Message ProcessTrust13ValidateResponse(Message message)
791 return ProcessCore(message,
792 _securityTokenServiceConfiguration.WSTrust13RequestSerializer,
793 _securityTokenServiceConfiguration.WSTrust13ResponseSerializer,
794 WSTrust13Constants.Actions.ValidateResponse,
795 WSTrust13Constants.Actions.ValidateFinalResponse,
796 WSTrust13Constants.NamespaceURI);
800 /// Processes a Trust Feb 2005 Cancel message synchronously.
802 /// <param name="message">Incoming Request message.</param>
803 /// <returns>Message with the serialized response.</returns>
804 public Message ProcessTrustFeb2005Cancel(Message message)
806 return ProcessCore(message, _securityTokenServiceConfiguration.WSTrustFeb2005RequestSerializer, _securityTokenServiceConfiguration.WSTrustFeb2005ResponseSerializer, WSTrustFeb2005Constants.Actions.Cancel, WSTrustFeb2005Constants.Actions.CancelResponse, WSTrustFeb2005Constants.NamespaceURI);
810 /// Processes a Trust Feb 2005 Issue message synchronously.
812 /// <param name="message">Incoming Request message.</param>
813 /// <returns>Message with the serialized response.</returns>
814 public Message ProcessTrustFeb2005Issue(Message message)
816 return ProcessCore(message, _securityTokenServiceConfiguration.WSTrustFeb2005RequestSerializer, _securityTokenServiceConfiguration.WSTrustFeb2005ResponseSerializer, WSTrustFeb2005Constants.Actions.Issue, WSTrustFeb2005Constants.Actions.IssueResponse, WSTrustFeb2005Constants.NamespaceURI);
820 /// Processes a Trust Feb 2005 Renew message synchronously.
822 /// <param name="message">Incoming Request message.</param>
823 /// <returns>Message with the serialized response.</returns>
824 public Message ProcessTrustFeb2005Renew(Message message)
826 return ProcessCore(message, _securityTokenServiceConfiguration.WSTrustFeb2005RequestSerializer, _securityTokenServiceConfiguration.WSTrustFeb2005ResponseSerializer, WSTrustFeb2005Constants.Actions.Renew, WSTrustFeb2005Constants.Actions.RenewResponse, WSTrustFeb2005Constants.NamespaceURI);
830 /// Processes a Trust Feb 2005 Validate message synchronously.
832 /// <param name="message">Incoming Request message.</param>
833 /// <returns>Message with the serialized response.</returns>
834 public Message ProcessTrustFeb2005Validate(Message message)
836 return ProcessCore(message, _securityTokenServiceConfiguration.WSTrustFeb2005RequestSerializer, _securityTokenServiceConfiguration.WSTrustFeb2005ResponseSerializer, WSTrustFeb2005Constants.Actions.Validate, WSTrustFeb2005Constants.Actions.ValidateResponse, WSTrustFeb2005Constants.NamespaceURI);
840 /// Processes a Trust Feb 2005 RSTR/Cancel message synchronously.
842 /// <param name="message">Incoming Request message.</param>
843 /// <returns>Message with the serialized response.</returns>
844 public Message ProcessTrustFeb2005CancelResponse(Message message)
846 return ProcessCore(message,
847 _securityTokenServiceConfiguration.WSTrustFeb2005RequestSerializer,
848 _securityTokenServiceConfiguration.WSTrustFeb2005ResponseSerializer,
849 WSTrustFeb2005Constants.Actions.CancelResponse,
850 WSTrustFeb2005Constants.Actions.CancelResponse,
851 WSTrustFeb2005Constants.NamespaceURI);
855 /// Processes a Trust Feb 2005 RSTR/Issue message synchronously.
857 /// <param name="message">Incoming Request message.</param>
858 /// <returns>Message with the serialized response.</returns>
859 public Message ProcessTrustFeb2005IssueResponse(Message message)
861 return ProcessCore(message,
862 _securityTokenServiceConfiguration.WSTrustFeb2005RequestSerializer,
863 _securityTokenServiceConfiguration.WSTrustFeb2005ResponseSerializer,
864 WSTrustFeb2005Constants.Actions.IssueResponse,
865 WSTrustFeb2005Constants.Actions.IssueResponse,
866 WSTrustFeb2005Constants.NamespaceURI);
870 /// Processes a Trust Feb 2005 RSTR/Renew message synchronously.
872 /// <param name="message">Incoming Request message.</param>
873 /// <returns>Message with the serialized response.</returns>
874 public Message ProcessTrustFeb2005RenewResponse(Message message)
876 return ProcessCore(message,
877 _securityTokenServiceConfiguration.WSTrustFeb2005RequestSerializer,
878 _securityTokenServiceConfiguration.WSTrustFeb2005ResponseSerializer,
879 WSTrustFeb2005Constants.Actions.RenewResponse,
880 WSTrustFeb2005Constants.Actions.RenewResponse,
881 WSTrustFeb2005Constants.NamespaceURI);
885 /// Processes a Trust Feb 2005 RSTR/Validate message synchronously.
887 /// <param name="message">Incoming Request message.</param>
888 /// <returns>Message with the serialized response.</returns>
889 public Message ProcessTrustFeb2005ValidateResponse(Message message)
891 return ProcessCore(message,
892 _securityTokenServiceConfiguration.WSTrustFeb2005RequestSerializer,
893 _securityTokenServiceConfiguration.WSTrustFeb2005ResponseSerializer,
894 WSTrustFeb2005Constants.Actions.ValidateResponse,
895 WSTrustFeb2005Constants.Actions.ValidateResponse,
896 WSTrustFeb2005Constants.NamespaceURI);
900 /// Gets the SecurityTokenServiceConfiguration
902 public SecurityTokenServiceConfiguration SecurityTokenServiceConfiguration
906 return _securityTokenServiceConfiguration;
912 #region IWSTrustFeb2005AsyncContract and IWSTrust13AsyncContract Methods
915 /// Processes an Asynchronous call to Trust Feb 1.3 Cancel message.
917 /// <param name="request">Incoming Request message.</param>
918 /// <param name="callback">Callback to be invoked when the Asynchronous operation ends.</param>
919 /// <param name="state">Asynchronous state.</param>
920 /// <returns>IAsyncResult that should be passed back to the End method to complete the Asynchronous call.</returns>
921 public IAsyncResult BeginTrust13Cancel(Message request, AsyncCallback callback, object state)
923 return BeginProcessCore(request, _securityTokenServiceConfiguration.WSTrust13RequestSerializer, _securityTokenServiceConfiguration.WSTrust13ResponseSerializer, WSTrust13Constants.Actions.Cancel, WSTrust13Constants.Actions.CancelFinalResponse, WSTrust13Constants.NamespaceURI, callback, state);
927 /// Completes an Asynchronous call to Trust 1.3 Cancel message.
929 /// <param name="ar">IAsyncResult object returned by the Begin method that started the Asynchronous call.</param>
930 /// <returns>Message containing the Serialized RSTR.</returns>
931 public Message EndTrust13Cancel(IAsyncResult ar)
933 return EndProcessCore(ar, WSTrust13Constants.Actions.Cancel, WSTrust13Constants.Actions.CancelFinalResponse, WSTrust13Constants.NamespaceURI);
937 /// Processes an Asynchronous call to Trust 1.3 Issue message.
939 /// <param name="request">Incoming Request message.</param>
940 /// <param name="callback">Callback to be invoked when the Asynchronous operation ends.</param>
941 /// <param name="state">Asynchronous state.</param>
942 /// <returns>IAsyncResult that should be passed back to the End method to complete the Asynchronous call.</returns>
943 public IAsyncResult BeginTrust13Issue(Message request, AsyncCallback callback, object state)
945 return BeginProcessCore(request, _securityTokenServiceConfiguration.WSTrust13RequestSerializer, _securityTokenServiceConfiguration.WSTrust13ResponseSerializer, WSTrust13Constants.Actions.Issue, WSTrust13Constants.Actions.IssueFinalResponse, WSTrust13Constants.NamespaceURI, callback, state);
949 /// Completes an Asynchronous call to Trust 1.3 Issue message.
951 /// <param name="ar">IAsyncResult object returned by the Begin method that started the Asynchronous call.</param>
952 /// <returns>Message containing the Serialized RSTR.</returns>
953 public Message EndTrust13Issue(IAsyncResult ar)
955 return EndProcessCore(ar, WSTrust13Constants.Actions.Issue, WSTrust13Constants.Actions.IssueFinalResponse, WSTrust13Constants.NamespaceURI);
959 /// Processes an Asynchronous call to Trust 1.3 Renew message.
961 /// <param name="request">Incoming Request message.</param>
962 /// <param name="callback">Callback to be invoked when the Asynchronous operation ends.</param>
963 /// <param name="state">Asynchronous state.</param>
964 /// <returns>IAsyncResult that should be passed back to the End method to complete the Asynchronous call.</returns>
965 public IAsyncResult BeginTrust13Renew(Message request, AsyncCallback callback, object state)
967 return BeginProcessCore(request, _securityTokenServiceConfiguration.WSTrust13RequestSerializer, _securityTokenServiceConfiguration.WSTrust13ResponseSerializer, WSTrust13Constants.Actions.Renew, WSTrust13Constants.Actions.RenewFinalResponse, WSTrust13Constants.NamespaceURI, callback, state);
971 /// Completes an Asynchronous call to Trust 1.3 Renew message.
973 /// <param name="ar">IAsyncResult object returned by the Begin method that started the Asynchronous call.</param>
974 /// <returns>Message containing the Serialized RSTR.</returns>
975 public Message EndTrust13Renew(IAsyncResult ar)
977 return EndProcessCore(ar, WSTrust13Constants.Actions.Renew, WSTrust13Constants.Actions.RenewFinalResponse, WSTrust13Constants.NamespaceURI);
981 /// Processes an Asynchronous call to Trust 1.3 Validate message.
983 /// <param name="request">Incoming Request message.</param>
984 /// <param name="callback">Callback to be invoked when the Asynchronous operation ends.</param>
985 /// <param name="state">Asynchronous state.</param>
986 /// <returns>IAsyncResult that should be passed back to the End method to complete the Asynchronous call.</returns>
987 public IAsyncResult BeginTrust13Validate(Message request, AsyncCallback callback, object state)
989 return BeginProcessCore(request, _securityTokenServiceConfiguration.WSTrust13RequestSerializer, _securityTokenServiceConfiguration.WSTrust13ResponseSerializer, WSTrust13Constants.Actions.Validate, WSTrust13Constants.Actions.ValidateFinalResponse, WSTrust13Constants.NamespaceURI, callback, state);
993 /// Completes an Asynchronous call to Trust 1.3 Validate message.
995 /// <param name="ar">IAsyncResult object returned by the Begin method that started the Asynchronous call.</param>
996 /// <returns>Message containing the Serialized RSTR.</returns>
997 public Message EndTrust13Validate(IAsyncResult ar)
999 return EndProcessCore(ar, WSTrust13Constants.Actions.Validate, WSTrust13Constants.Actions.ValidateFinalResponse, WSTrust13Constants.NamespaceURI);
1003 /// Processes an Asynchronous call to Trust 1.3 RSTR/Cancel message.
1005 /// <param name="request">Incoming Request message.</param>
1006 /// <param name="callback">Callback to be invoked when the Asynchronous operation ends.</param>
1007 /// <param name="state">Asynchronous state.</param>
1008 /// <returns>IAsyncResult that should be passed back to the End method to complete the Asynchronous call.</returns>
1009 public IAsyncResult BeginTrust13CancelResponse(Message request, AsyncCallback callback, object state)
1011 return BeginProcessCore(request,
1012 _securityTokenServiceConfiguration.WSTrust13RequestSerializer,
1013 _securityTokenServiceConfiguration.WSTrust13ResponseSerializer,
1014 WSTrust13Constants.Actions.CancelResponse,
1015 WSTrust13Constants.Actions.CancelFinalResponse,
1016 WSTrust13Constants.NamespaceURI,
1022 /// Completes an Asynchronous call to Trust 1.3 RSTR/Cancel message.
1024 /// <param name="ar">IAsyncResult object returned by the Begin method that started the Asynchronous call.</param>
1025 /// <returns>Message containing the Serialized RSTR.</returns>
1026 public Message EndTrust13CancelResponse(IAsyncResult ar)
1028 return EndProcessCore(ar,
1029 WSTrust13Constants.Actions.CancelResponse,
1030 WSTrust13Constants.Actions.CancelFinalResponse,
1031 WSTrust13Constants.NamespaceURI);
1035 /// Processes an Asynchronous call to Trust 1.3 RSTR/Issue message.
1037 /// <param name="request">Incoming Request message.</param>
1038 /// <param name="callback">Callback to be invoked when the Asynchronous operation ends.</param>
1039 /// <param name="state">Asynchronous state.</param>
1040 /// <returns>IAsyncResult that should be passed back to the End method to complete the Asynchronous call.</returns>
1041 public IAsyncResult BeginTrust13IssueResponse(Message request, AsyncCallback callback, object state)
1043 return BeginProcessCore(request,
1044 _securityTokenServiceConfiguration.WSTrust13RequestSerializer,
1045 _securityTokenServiceConfiguration.WSTrust13ResponseSerializer,
1046 WSTrust13Constants.Actions.IssueResponse,
1047 WSTrust13Constants.Actions.IssueFinalResponse,
1048 WSTrust13Constants.NamespaceURI,
1054 /// Completes an Asynchronous call to Trust 1.3 RSTR/Issue message.
1056 /// <param name="ar">IAsyncResult object returned by the Begin method that started the Asynchronous call.</param>
1057 /// <returns>Message containing the Serialized RSTR.</returns>
1058 public Message EndTrust13IssueResponse(IAsyncResult ar)
1060 return EndProcessCore(ar,
1061 WSTrust13Constants.Actions.IssueResponse,
1062 WSTrust13Constants.Actions.IssueFinalResponse,
1063 WSTrust13Constants.NamespaceURI);
1067 /// Processes an Asynchronous call to Trust 1.3 RSTR/Renew message.
1069 /// <param name="request">Incoming Request message.</param>
1070 /// <param name="callback">Callback to be invoked when the Asynchronous operation ends.</param>
1071 /// <param name="state">Asynchronous state.</param>
1072 /// <returns>IAsyncResult that should be passed back to the End method to complete the Asynchronous call.</returns>
1073 public IAsyncResult BeginTrust13RenewResponse(Message request, AsyncCallback callback, object state)
1075 return BeginProcessCore(request,
1076 _securityTokenServiceConfiguration.WSTrust13RequestSerializer,
1077 _securityTokenServiceConfiguration.WSTrust13ResponseSerializer,
1078 WSTrust13Constants.Actions.RenewResponse,
1079 WSTrust13Constants.Actions.RenewFinalResponse,
1080 WSTrust13Constants.NamespaceURI,
1086 /// Completes an Asynchronous call to Trust 1.3 RSTR/Renew message.
1088 /// <param name="ar">IAsyncResult object returned by the Begin method that started the Asynchronous call.</param>
1089 /// <returns>Message containing the Serialized RSTR.</returns>
1090 public Message EndTrust13RenewResponse(IAsyncResult ar)
1092 return EndProcessCore(ar,
1093 WSTrust13Constants.Actions.RenewResponse,
1094 WSTrust13Constants.Actions.RenewFinalResponse,
1095 WSTrust13Constants.NamespaceURI);
1099 /// Processes an Asynchronous call to Trust 1.3 RSTR/Validate message.
1101 /// <param name="request">Incoming Request message.</param>
1102 /// <param name="callback">Callback to be invoked when the Asynchronous operation ends.</param>
1103 /// <param name="state">Asynchronous state.</param>
1104 /// <returns>IAsyncResult that should be passed back to the End method to complete the Asynchronous call.</returns>
1105 public IAsyncResult BeginTrust13ValidateResponse(Message request, AsyncCallback callback, object state)
1107 return BeginProcessCore(request,
1108 _securityTokenServiceConfiguration.WSTrust13RequestSerializer,
1109 _securityTokenServiceConfiguration.WSTrust13ResponseSerializer,
1110 WSTrust13Constants.Actions.ValidateResponse,
1111 WSTrust13Constants.Actions.ValidateFinalResponse,
1112 WSTrust13Constants.NamespaceURI,
1118 /// Completes an Asynchronous call to Trust 1.3 RSTR/Validate message.
1120 /// <param name="ar">IAsyncResult object returned by the Begin method that started the Asynchronous call.</param>
1121 /// <returns>Message containing the Serialized RSTR.</returns>
1122 public Message EndTrust13ValidateResponse(IAsyncResult ar)
1124 return EndProcessCore(ar,
1125 WSTrust13Constants.Actions.ValidateResponse,
1126 WSTrust13Constants.Actions.ValidateFinalResponse,
1127 WSTrust13Constants.NamespaceURI);
1131 /// Processes an Asynchronous call to Trust 2005 Cancel message.
1133 /// <param name="request">Incoming Request message.</param>
1134 /// <param name="callback">Callback to be invoked when the Asynchronous operation ends.</param>
1135 /// <param name="state">Asynchronous state.</param>
1136 /// <returns>IAsyncResult that should be passed back to the End method to complete the Asynchronous call.</returns>
1137 public IAsyncResult BeginTrustFeb2005Cancel(Message request, AsyncCallback callback, object state)
1139 return BeginProcessCore(request, _securityTokenServiceConfiguration.WSTrustFeb2005RequestSerializer, _securityTokenServiceConfiguration.WSTrustFeb2005ResponseSerializer, WSTrustFeb2005Constants.Actions.Cancel, WSTrustFeb2005Constants.Actions.CancelResponse, WSTrustFeb2005Constants.NamespaceURI, callback, state);
1143 /// Completes an Asynchronous call to Trust Feb 2005 Cancel message.
1145 /// <param name="ar">IAsyncResult object returned by the Begin method that started the Asynchronous call.</param>
1146 /// <returns>Message containing the Serialized RSTR.</returns>
1147 public Message EndTrustFeb2005Cancel(IAsyncResult ar)
1149 return EndProcessCore(ar, WSTrustFeb2005Constants.Actions.Cancel, WSTrustFeb2005Constants.Actions.CancelResponse, WSTrustFeb2005Constants.NamespaceURI);
1153 /// Processes an Asynchronous call to Trust Feb 2005 Issue message.
1155 /// <param name="request">Incoming Request message.</param>
1156 /// <param name="callback">Callback to be invoked when the Asynchronous operation ends.</param>
1157 /// <param name="state">Asynchronous state.</param>
1158 /// <returns>IAsyncResult that should be passed back to the End method to complete the Asynchronous call.</returns>
1159 public IAsyncResult BeginTrustFeb2005Issue(Message request, AsyncCallback callback, object state)
1161 return BeginProcessCore(request, _securityTokenServiceConfiguration.WSTrustFeb2005RequestSerializer, _securityTokenServiceConfiguration.WSTrustFeb2005ResponseSerializer, WSTrustFeb2005Constants.Actions.Issue, WSTrustFeb2005Constants.Actions.IssueResponse, WSTrustFeb2005Constants.NamespaceURI, callback, state);
1165 /// Completes an Asynchronous call to Trust Feb 2005 Issue message.
1167 /// <param name="ar">IAsyncResult object returned by the Begin method that started the Asynchronous call.</param>
1168 /// <returns>Message containing the Serialized RSTR.</returns>
1169 public Message EndTrustFeb2005Issue(IAsyncResult ar)
1171 return EndProcessCore(ar, WSTrustFeb2005Constants.Actions.Issue, WSTrustFeb2005Constants.Actions.IssueResponse, WSTrustFeb2005Constants.NamespaceURI);
1175 /// Processes an Asynchronous call to Trust Feb 2005 Renew message.
1177 /// <param name="request">Incoming Request message.</param>
1178 /// <param name="callback">Callback to be invoked when the Asynchronous operation ends.</param>
1179 /// <param name="state">Asynchronous state.</param>
1180 /// <returns>IAsyncResult that should be passed back to the End method to complete the Asynchronous call.</returns>
1181 public IAsyncResult BeginTrustFeb2005Renew(Message request, AsyncCallback callback, object state)
1183 return BeginProcessCore(request, _securityTokenServiceConfiguration.WSTrustFeb2005RequestSerializer, _securityTokenServiceConfiguration.WSTrustFeb2005ResponseSerializer, WSTrustFeb2005Constants.Actions.Renew, WSTrustFeb2005Constants.Actions.RenewResponse, WSTrustFeb2005Constants.NamespaceURI, callback, state);
1187 /// Completes an Asynchronous call to Trust Feb 2005 Renew message.
1189 /// <param name="ar">IAsyncResult object returned by the Begin method that started the Asynchronous call.</param>
1190 /// <returns>Message containing the Serialized RSTR.</returns>
1191 public Message EndTrustFeb2005Renew(IAsyncResult ar)
1193 return EndProcessCore(ar, WSTrustFeb2005Constants.Actions.Renew, WSTrustFeb2005Constants.Actions.RenewResponse, WSTrustFeb2005Constants.NamespaceURI);
1197 /// Processes an Asynchronous call to Trust Feb 2005 Validate message.
1199 /// <param name="request">Incoming Request message.</param>
1200 /// <param name="callback">Callback to be invoked when the Asynchronous operation ends.</param>
1201 /// <param name="state">Asynchronous state.</param>
1202 /// <returns>IAsyncResult that should be passed back to the End method to complete the Asynchronous call.</returns>
1203 public IAsyncResult BeginTrustFeb2005Validate(Message request, AsyncCallback callback, object state)
1205 return BeginProcessCore(request, _securityTokenServiceConfiguration.WSTrustFeb2005RequestSerializer, _securityTokenServiceConfiguration.WSTrustFeb2005ResponseSerializer, WSTrustFeb2005Constants.Actions.Validate, WSTrustFeb2005Constants.Actions.ValidateResponse, WSTrustFeb2005Constants.NamespaceURI, callback, state);
1209 /// Completes an Asynchronous call to Trust Feb 2005 Validate message.
1211 /// <param name="ar">IAsyncResult object returned by the Begin method that started the Asynchronous call.</param>
1212 /// <returns>Message containing the Serialized RSTR.</returns>
1213 public Message EndTrustFeb2005Validate(IAsyncResult ar)
1215 return EndProcessCore(ar, WSTrustFeb2005Constants.Actions.Validate, WSTrustFeb2005Constants.Actions.ValidateResponse, WSTrustFeb2005Constants.NamespaceURI);
1219 /// Processes an Asynchronous call to Trust Feb 2005 RSTR/Cancel message.
1221 /// <param name="request">Incoming Request message.</param>
1222 /// <param name="callback">Callback to be invoked when the Asynchronous operation ends.</param>
1223 /// <param name="state">Asynchronous state.</param>
1224 /// <returns>IAsyncResult that should be passed back to the End method to complete the Asynchronous call.</returns>
1225 public IAsyncResult BeginTrustFeb2005CancelResponse(Message request, AsyncCallback callback, object state)
1227 return BeginProcessCore(request,
1228 _securityTokenServiceConfiguration.WSTrustFeb2005RequestSerializer,
1229 _securityTokenServiceConfiguration.WSTrustFeb2005ResponseSerializer,
1230 WSTrustFeb2005Constants.Actions.CancelResponse,
1231 WSTrustFeb2005Constants.Actions.CancelResponse,
1232 WSTrustFeb2005Constants.NamespaceURI,
1238 /// Completes an Asynchronous call to Trust Feb 2005 RSTR/Cancel message.
1240 /// <param name="ar">IAsyncResult object returned by the Begin method that started the Asynchronous call.</param>
1241 /// <returns>Message containing the Serialized RSTR.</returns>
1242 public Message EndTrustFeb2005CancelResponse(IAsyncResult ar)
1244 return EndProcessCore(ar,
1245 WSTrustFeb2005Constants.Actions.CancelResponse,
1246 WSTrustFeb2005Constants.Actions.CancelResponse,
1247 WSTrustFeb2005Constants.NamespaceURI);
1251 /// Processes an Asynchronous call to Trust Feb 2005 RSTR/Issue message.
1253 /// <param name="request">Incoming Request message.</param>
1254 /// <param name="callback">Callback to be invoked when the Asynchronous operation ends.</param>
1255 /// <param name="state">Asynchronous state.</param>
1256 /// <returns>IAsyncResult that should be passed back to the End method to complete the Asynchronous call.</returns>
1257 public IAsyncResult BeginTrustFeb2005IssueResponse(Message request, AsyncCallback callback, object state)
1259 return BeginProcessCore(request,
1260 _securityTokenServiceConfiguration.WSTrustFeb2005RequestSerializer,
1261 _securityTokenServiceConfiguration.WSTrustFeb2005ResponseSerializer,
1262 WSTrustFeb2005Constants.Actions.IssueResponse,
1263 WSTrustFeb2005Constants.Actions.IssueResponse,
1264 WSTrustFeb2005Constants.NamespaceURI,
1270 /// Completes an Asynchronous call to Trust Feb 2005 RSTR/Issue message.
1272 /// <param name="ar">IAsyncResult object returned by the Begin method that started the Asynchronous call.</param>
1273 /// <returns>Message containing the Serialized RSTR.</returns>
1274 public Message EndTrustFeb2005IssueResponse(IAsyncResult ar)
1276 return EndProcessCore(ar,
1277 WSTrustFeb2005Constants.Actions.IssueResponse,
1278 WSTrustFeb2005Constants.Actions.IssueResponse,
1279 WSTrustFeb2005Constants.NamespaceURI);
1283 /// Processes an Asynchronous call to Trust Feb 2005 RSTR/Renew message.
1285 /// <param name="request">Incoming Request message.</param>
1286 /// <param name="callback">Callback to be invoked when the Asynchronous operation ends.</param>
1287 /// <param name="state">Asynchronous state.</param>
1288 /// <returns>IAsyncResult that should be passed back to the End method to complete the Asynchronous call.</returns>
1289 public IAsyncResult BeginTrustFeb2005RenewResponse(Message request, AsyncCallback callback, object state)
1291 return BeginProcessCore(request,
1292 _securityTokenServiceConfiguration.WSTrustFeb2005RequestSerializer,
1293 _securityTokenServiceConfiguration.WSTrustFeb2005ResponseSerializer,
1294 WSTrustFeb2005Constants.Actions.RenewResponse,
1295 WSTrustFeb2005Constants.Actions.RenewResponse,
1296 WSTrustFeb2005Constants.NamespaceURI,
1302 /// Completes an Asynchronous call to Trust Feb 2005 RSTR/Renew message.
1304 /// <param name="ar">IAsyncResult object returned by the Begin method that started the Asynchronous call.</param>
1305 /// <returns>Message containing the Serialized RSTR.</returns>
1306 public Message EndTrustFeb2005RenewResponse(IAsyncResult ar)
1308 return EndProcessCore(ar,
1309 WSTrustFeb2005Constants.Actions.RenewResponse,
1310 WSTrustFeb2005Constants.Actions.RenewResponse,
1311 WSTrustFeb2005Constants.NamespaceURI);
1315 /// Processes an Asynchronous call to Trust Feb 2005 RSTR/Validate message.
1317 /// <param name="request">Incoming Request message.</param>
1318 /// <param name="callback">Callback to be invoked when the Asynchronous operation ends.</param>
1319 /// <param name="state">Asynchronous state.</param>
1320 /// <returns>IAsyncResult that should be passed back to the End method to complete the Asynchronous call.</returns>
1321 public IAsyncResult BeginTrustFeb2005ValidateResponse(Message request, AsyncCallback callback, object state)
1323 return BeginProcessCore(request,
1324 _securityTokenServiceConfiguration.WSTrustFeb2005RequestSerializer,
1325 _securityTokenServiceConfiguration.WSTrustFeb2005ResponseSerializer,
1326 WSTrustFeb2005Constants.Actions.ValidateResponse,
1327 WSTrustFeb2005Constants.Actions.ValidateResponse,
1328 WSTrustFeb2005Constants.NamespaceURI,
1334 /// Completes an Asynchronous call to Trust Feb 2005 RSTR/Validate message.
1336 /// <param name="ar">IAsyncResult object returned by the Begin method that started the Asynchronous call.</param>
1337 /// <returns>Message containing the Serialized RSTR.</returns>
1338 public Message EndTrustFeb2005ValidateResponse(IAsyncResult ar)
1340 return EndProcessCore(ar,
1341 WSTrustFeb2005Constants.Actions.ValidateResponse,
1342 WSTrustFeb2005Constants.Actions.ValidateResponse,
1343 WSTrustFeb2005Constants.NamespaceURI);
1349 // An async result class that represents the async version of the ProcessCore method.
1351 internal class ProcessCoreAsyncResult : AsyncResult
1354 // Encapsulate the local variables in the sync version of ProcessCore as fields.
1356 WSTrustServiceContract _trustServiceContract;
1357 DispatchContext _dispatchContext;
1358 MessageVersion _messageVersion;
1359 WSTrustResponseSerializer _responseSerializer;
1360 WSTrustSerializationContext _serializationContext;
1362 public ProcessCoreAsyncResult(WSTrustServiceContract contract,
1363 DispatchContext dispatchContext,
1364 MessageVersion messageVersion,
1365 WSTrustResponseSerializer responseSerializer,
1366 WSTrustSerializationContext serializationContext,
1367 AsyncCallback asyncCallback,
1369 : base(asyncCallback, asyncState)
1371 if (contract == null)
1373 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contract");
1376 if (dispatchContext == null)
1378 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dispatchContext");
1381 if (responseSerializer == null)
1383 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("responseSerializer");
1386 if (serializationContext == null)
1388 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serializationContext");
1391 _trustServiceContract = contract;
1392 _dispatchContext = dispatchContext;
1393 _messageVersion = messageVersion;
1394 _responseSerializer = responseSerializer;
1395 _serializationContext = serializationContext;
1397 contract.BeginDispatchRequest(dispatchContext, OnDispatchRequestCompleted, null);
1400 public WSTrustServiceContract TrustServiceContract
1402 get { return _trustServiceContract; }
1405 public DispatchContext DispatchContext
1407 get { return _dispatchContext; }
1410 public MessageVersion MessageVersion
1412 get { return _messageVersion; }
1415 public WSTrustResponseSerializer ResponseSerializer
1417 get { return _responseSerializer; }
1420 public WSTrustSerializationContext SerializationContext
1422 get { return _serializationContext; }
1425 public new static Message End(IAsyncResult ar)
1427 AsyncResult.End(ar);
1429 ProcessCoreAsyncResult pcar = ar as ProcessCoreAsyncResult;
1432 throw DiagnosticUtility.ThrowHelperInvalidOperation(SR.GetString(SR.ID2004, typeof(ProcessCoreAsyncResult), ar.GetType()));
1436 // Create the response Message object with the appropriate action.
1438 return Message.CreateMessage(OperationContext.Current.RequestContext.RequestMessage.Version,
1439 pcar.DispatchContext.ResponseAction,
1440 new WSTrustResponseBodyWriter(pcar.DispatchContext.ResponseMessage,
1441 pcar.ResponseSerializer,
1442 pcar.SerializationContext));
1446 // Asynchronously invoked when WSTrustServiceContract.BeginDispatchRequest completes.
1448 private void OnDispatchRequestCompleted(IAsyncResult ar)
1452 _dispatchContext = _trustServiceContract.EndDispatchRequest(ar);
1453 this.Complete(false);
1455 catch (Exception ex)
1457 if (System.Runtime.Fx.IsFatal(ex))
1461 this.Complete(false, ex);
1467 // AsyncResult to encapsulate the default async implementation of DispatchRequest
1469 internal class DispatchRequestAsyncResult : AsyncResult
1471 DispatchContext _dispatchContext;
1473 public DispatchContext DispatchContext
1475 get { return _dispatchContext; }
1478 public DispatchRequestAsyncResult(DispatchContext dispatchContext, AsyncCallback asyncCallback, object asyncState)
1479 : base(asyncCallback, asyncState)
1481 _dispatchContext = dispatchContext;
1483 ClaimsPrincipal icp = dispatchContext.Principal;
1484 RST rst = dispatchContext.RequestMessage as RST;
1485 STS sts = dispatchContext.SecurityTokenService;
1489 this.Complete(true, DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidRequestException(SR.GetString(SR.ID3023))));
1493 switch (rst.RequestType)
1495 case RequestTypes.Cancel:
1496 sts.BeginCancel(icp, rst, OnCancelComplete, null);
1498 case RequestTypes.Issue:
1499 sts.BeginIssue(icp, rst, OnIssueComplete, null);
1501 case RequestTypes.Renew:
1502 sts.BeginRenew(icp, rst, OnRenewComplete, null);
1504 case RequestTypes.Validate:
1505 sts.BeginValidate(icp, rst, OnValidateComplete, null);
1508 this.Complete(true, DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ID3112, rst.RequestType))));
1513 public new static DispatchContext End(IAsyncResult ar)
1515 AsyncResult.End(ar);
1517 DispatchRequestAsyncResult dcar = ar as DispatchRequestAsyncResult;
1520 throw DiagnosticUtility.ThrowHelperInvalidOperation(SR.GetString(SR.ID2004, typeof(DispatchRequestAsyncResult), ar.GetType()));
1522 return dcar.DispatchContext;
1525 void OnCancelComplete(IAsyncResult ar)
1529 _dispatchContext.ResponseMessage = _dispatchContext.SecurityTokenService.EndCancel(ar);
1534 System.ServiceModel.DiagnosticUtility.TraceHandledException(e, TraceEventType.Error);
1536 if (Fx.IsFatal(e)) throw;
1541 void OnIssueComplete(IAsyncResult ar)
1545 _dispatchContext.ResponseMessage = _dispatchContext.SecurityTokenService.EndIssue(ar);
1550 System.ServiceModel.DiagnosticUtility.TraceHandledException(e, TraceEventType.Error);
1552 if (Fx.IsFatal(e)) throw;
1557 void OnRenewComplete(IAsyncResult ar)
1561 _dispatchContext.ResponseMessage = _dispatchContext.SecurityTokenService.EndRenew(ar);
1566 System.ServiceModel.DiagnosticUtility.TraceHandledException(e, TraceEventType.Error);
1568 if (Fx.IsFatal(e)) throw;
1573 void OnValidateComplete(IAsyncResult ar)
1577 _dispatchContext.ResponseMessage = _dispatchContext.SecurityTokenService.EndValidate(ar);
1582 System.ServiceModel.DiagnosticUtility.TraceHandledException(e, TraceEventType.Error);
1584 if (Fx.IsFatal(e)) throw;
1591 #region IContractBehavior Members
1594 /// Configures any binding elements to support the contract behavior.
1597 /// Inherited from IContractBehavior
1599 public void AddBindingParameters(ContractDescription contractDescription, ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
1605 /// Implements a modification or extension of the client across a contract.
1608 /// Inherited from IContractBehavior
1610 public void ApplyClientBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
1616 /// Implements a modification or extension of the client across a contract.
1619 /// Inherited from IContractBehavior
1621 public void ApplyDispatchBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.DispatchRuntime dispatchRuntime)
1627 /// Implement to confirm that the contract and endpoint can support the contract
1631 /// Inherited from IContractBehavior
1633 public void Validate(ContractDescription contractDescription, ServiceEndpoint endpoint)
1640 #region IWsdlExportExtension Members
1643 /// Implementation for IWsdlExportExtension.ExportContract. The default implementation
1644 /// does nothing. Can be overriden in the derived class for specific behavior.
1646 /// <param name="exporter">The WsdlExporter that exports the contract information.</param>
1647 /// <param name="context">Provides mappings from exported WSDL elements to the contract description.</param>
1648 public virtual void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)
1654 /// Implements IWsdlExportExtensions.ExportEndpoint. The default implementation does the following,
1655 /// For every Trust contract found,
1656 /// 1. It includes the appropriate trust namespace in the WSDL.
1657 /// 2. Imports the appropriate Trust schema and all dependent schemas.
1658 /// 3. Fixes the Messages of each operation to it appropriate WS-Trust equivalent.
1659 /// Trust Contract exposed by the Framework takes a System.ServiceModel.Channels.Message in and
1660 /// returns a System.ServiceModel.Channels.Message out. But Trust messages expects and RST and
1661 /// returns an RSTR/RSTRC. This method fixes the message names with the appropriate WS-Trust
1664 /// <param name="exporter">The WsdlExporter that exports the contract information.</param>
1665 /// <param name="context">Provides mappings from exported WSDL elements to the endpoint description.</param>
1666 /// <exception cref="ArgumentNullException">The input argument 'exporter' or 'context' is null.</exception>
1667 public virtual void ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context)
1669 if (exporter == null)
1671 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("exporter");
1674 if (context == null)
1676 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
1679 if (context.WsdlPort == null)
1681 throw DiagnosticUtility.ThrowHelperInvalidOperation(SR.GetString(SR.ID3146));
1684 if (context.WsdlPort.Service == null)
1686 throw DiagnosticUtility.ThrowHelperInvalidOperation(SR.GetString(SR.ID3147));
1689 if (context.WsdlPort.Service.ServiceDescription == null)
1691 throw DiagnosticUtility.ThrowHelperInvalidOperation(SR.GetString(SR.ID3148));
1694 System.Web.Services.Description.ServiceDescription serviceDescription = context.WsdlPort.Service.ServiceDescription;
1696 // Iterate throught the Ports and for each of our contracts fix the input and output messages
1697 // of the contract and import the required schemas.
1698 foreach (PortType portType in serviceDescription.PortTypes)
1700 if (StringComparer.Ordinal.Equals(portType.Name, WSTrustServiceContractConstants.Contracts.IWSTrustFeb2005Sync))
1702 IncludeNamespace(context, WSTrustFeb2005Constants.Prefix, WSTrustFeb2005Constants.NamespaceURI);
1703 ImportSchema(exporter, context, WSTrustFeb2005Constants.NamespaceURI);
1709 WSTrustServiceContractConstants.Operations.TrustFeb2005Cancel,
1710 new XmlQualifiedName(
1711 WSTrustFeb2005Constants.ElementNames.RequestSecurityToken,
1712 WSTrustFeb2005Constants.NamespaceURI),
1713 new XmlQualifiedName(WSTrustFeb2005Constants.ElementNames.RequestSecurityTokenResponse,
1714 WSTrustFeb2005Constants.NamespaceURI));
1720 WSTrustServiceContractConstants.Operations.TrustFeb2005Issue,
1721 new XmlQualifiedName(
1722 WSTrustFeb2005Constants.ElementNames.RequestSecurityToken,
1723 WSTrustFeb2005Constants.NamespaceURI),
1724 new XmlQualifiedName(
1725 WSTrustFeb2005Constants.ElementNames.RequestSecurityTokenResponse,
1726 WSTrustFeb2005Constants.NamespaceURI));
1732 WSTrustServiceContractConstants.Operations.TrustFeb2005Renew,
1733 new XmlQualifiedName(
1734 WSTrustFeb2005Constants.ElementNames.RequestSecurityToken,
1735 WSTrustFeb2005Constants.NamespaceURI),
1736 new XmlQualifiedName(
1737 WSTrustFeb2005Constants.ElementNames.RequestSecurityTokenResponse,
1738 WSTrustFeb2005Constants.NamespaceURI));
1744 WSTrustServiceContractConstants.Operations.TrustFeb2005Validate,
1745 new XmlQualifiedName(
1746 WSTrustFeb2005Constants.ElementNames.RequestSecurityToken,
1747 WSTrustFeb2005Constants.NamespaceURI),
1748 new XmlQualifiedName(
1749 WSTrustFeb2005Constants.ElementNames.RequestSecurityTokenResponse,
1750 WSTrustFeb2005Constants.NamespaceURI));
1752 else if (StringComparer.OrdinalIgnoreCase.Equals(portType.Name, WSTrustServiceContractConstants.Contracts.IWSTrust13Sync))
1754 IncludeNamespace(context, WSTrust13Constants.Prefix, WSTrust13Constants.NamespaceURI);
1755 ImportSchema(exporter, context, WSTrust13Constants.NamespaceURI);
1761 WSTrustServiceContractConstants.Operations.Trust13Cancel,
1762 new XmlQualifiedName(
1763 WSTrust13Constants.ElementNames.RequestSecurityToken,
1764 WSTrust13Constants.NamespaceURI),
1765 new XmlQualifiedName(
1766 WSTrust13Constants.ElementNames.RequestSecurityTokenResponseCollection,
1767 WSTrust13Constants.NamespaceURI));
1773 WSTrustServiceContractConstants.Operations.Trust13Issue,
1774 new XmlQualifiedName(
1775 WSTrust13Constants.ElementNames.RequestSecurityToken,
1776 WSTrust13Constants.NamespaceURI),
1777 new XmlQualifiedName(
1778 WSTrust13Constants.ElementNames.RequestSecurityTokenResponseCollection,
1779 WSTrust13Constants.NamespaceURI));
1785 WSTrustServiceContractConstants.Operations.Trust13Renew,
1786 new XmlQualifiedName(
1787 WSTrust13Constants.ElementNames.RequestSecurityToken,
1788 WSTrust13Constants.NamespaceURI),
1789 new XmlQualifiedName(
1790 WSTrust13Constants.ElementNames.RequestSecurityTokenResponseCollection,
1791 WSTrust13Constants.NamespaceURI));
1797 WSTrustServiceContractConstants.Operations.Trust13Validate,
1798 new XmlQualifiedName(
1799 WSTrust13Constants.ElementNames.RequestSecurityToken,
1800 WSTrust13Constants.NamespaceURI),
1801 new XmlQualifiedName(
1802 WSTrust13Constants.ElementNames.RequestSecurityTokenResponseCollection,
1803 WSTrust13Constants.NamespaceURI));
1805 else if (StringComparer.OrdinalIgnoreCase.Equals(portType.Name, WSTrustServiceContractConstants.Contracts.IWSTrustFeb2005Async))
1807 IncludeNamespace(context, WSTrustFeb2005Constants.Prefix, WSTrustFeb2005Constants.NamespaceURI);
1808 ImportSchema(exporter, context, WSTrustFeb2005Constants.NamespaceURI);
1814 WSTrustServiceContractConstants.Operations.TrustFeb2005CancelAsync,
1815 new XmlQualifiedName(
1816 WSTrustFeb2005Constants.ElementNames.RequestSecurityToken,
1817 WSTrustFeb2005Constants.NamespaceURI),
1818 new XmlQualifiedName(
1819 WSTrustFeb2005Constants.ElementNames.RequestSecurityTokenResponse,
1820 WSTrustFeb2005Constants.NamespaceURI));
1826 WSTrustServiceContractConstants.Operations.TrustFeb2005IssueAsync,
1827 new XmlQualifiedName(
1828 WSTrustFeb2005Constants.ElementNames.RequestSecurityToken,
1829 WSTrustFeb2005Constants.NamespaceURI),
1830 new XmlQualifiedName(
1831 WSTrustFeb2005Constants.ElementNames.RequestSecurityTokenResponse,
1832 WSTrustFeb2005Constants.NamespaceURI));
1838 WSTrustServiceContractConstants.Operations.TrustFeb2005RenewAsync,
1839 new XmlQualifiedName(
1840 WSTrustFeb2005Constants.ElementNames.RequestSecurityToken,
1841 WSTrustFeb2005Constants.NamespaceURI),
1842 new XmlQualifiedName(
1843 WSTrustFeb2005Constants.ElementNames.RequestSecurityTokenResponse,
1844 WSTrustFeb2005Constants.NamespaceURI));
1850 WSTrustServiceContractConstants.Operations.TrustFeb2005ValidateAsync,
1851 new XmlQualifiedName(
1852 WSTrustFeb2005Constants.ElementNames.RequestSecurityToken,
1853 WSTrustFeb2005Constants.NamespaceURI),
1854 new XmlQualifiedName(
1855 WSTrustFeb2005Constants.ElementNames.RequestSecurityTokenResponse,
1856 WSTrustFeb2005Constants.NamespaceURI));
1858 else if (StringComparer.OrdinalIgnoreCase.Equals(portType.Name, WSTrustServiceContractConstants.Contracts.IWSTrust13Async))
1860 IncludeNamespace(context, WSTrust13Constants.Prefix, WSTrust13Constants.NamespaceURI);
1861 ImportSchema(exporter, context, WSTrust13Constants.NamespaceURI);
1867 WSTrustServiceContractConstants.Operations.Trust13CancelAsync,
1868 new XmlQualifiedName(
1869 WSTrust13Constants.ElementNames.RequestSecurityToken,
1870 WSTrust13Constants.NamespaceURI),
1871 new XmlQualifiedName(
1872 WSTrust13Constants.ElementNames.RequestSecurityTokenResponseCollection,
1873 WSTrust13Constants.NamespaceURI));
1879 WSTrustServiceContractConstants.Operations.Trust13IssueAsync,
1880 new XmlQualifiedName(
1881 WSTrust13Constants.ElementNames.RequestSecurityToken,
1882 WSTrust13Constants.NamespaceURI),
1883 new XmlQualifiedName(
1884 WSTrust13Constants.ElementNames.RequestSecurityTokenResponseCollection,
1885 WSTrust13Constants.NamespaceURI));
1891 WSTrustServiceContractConstants.Operations.Trust13RenewAsync,
1892 new XmlQualifiedName(
1893 WSTrust13Constants.ElementNames.RequestSecurityToken,
1894 WSTrust13Constants.NamespaceURI),
1895 new XmlQualifiedName(
1896 WSTrust13Constants.ElementNames.RequestSecurityTokenResponseCollection,
1897 WSTrust13Constants.NamespaceURI));
1903 WSTrustServiceContractConstants.Operations.Trust13ValidateAsync,
1904 new XmlQualifiedName(
1905 WSTrust13Constants.ElementNames.RequestSecurityToken,
1906 WSTrust13Constants.NamespaceURI),
1907 new XmlQualifiedName(
1908 WSTrust13Constants.ElementNames.RequestSecurityTokenResponseCollection,
1909 WSTrust13Constants.NamespaceURI));
1917 /// Adds the required WS-Trust namespaces to the WSDL if not already present.
1919 /// <param name="context">Provides mappings from exported WSDL elements to the endpoint description.</param>
1920 /// <param name="prefix">The prefix of the namespace to be included.</param>
1921 /// <param name="ns">Namespace to be included.</param>
1922 /// <exception cref="ArgumentException">Either 'prefix' or 'ns' is null or empty string.</exception>
1923 /// <exception cref="ArgumentNullException">The 'context' parameter is null.</exception>
1924 protected virtual void IncludeNamespace(WsdlEndpointConversionContext context, string prefix, string ns)
1926 if (context == null)
1928 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
1931 if (String.IsNullOrEmpty(prefix))
1933 throw DiagnosticUtility.ThrowHelperArgumentNullOrEmptyString("prefix");
1936 if (String.IsNullOrEmpty(ns))
1938 throw DiagnosticUtility.ThrowHelperArgumentNullOrEmptyString("ns");
1941 bool alreadyPresent = false;
1942 XmlQualifiedName[] namespaces = context.WsdlBinding.ServiceDescription.Namespaces.ToArray();
1943 for (int i = 0; i < namespaces.Length; ++i)
1945 if (StringComparer.Ordinal.Equals(namespaces[i].Namespace, ns))
1947 alreadyPresent = true;
1952 if (!alreadyPresent)
1954 context.WsdlBinding.ServiceDescription.Namespaces.Add(prefix, ns);
1959 /// Imports all the required schema if not already present in the WSDL.
1960 /// The default implementation will import the following schemas,
1961 /// (a) WS-Trust Feb 2005.
1962 /// (b) WS-Trust 1.3
1963 /// Derived classes can override this method to import other schemas.
1965 /// <param name="exporter">The WsdlExporter that exports the contract information.</param>
1966 /// <param name="context">Provides mappings from exported WSDL elements to the endpoint description.</param>
1967 /// <param name="ns">The current WS-Trust namespace for which the schemas are imported.</param>
1968 /// <exception cref="ArgumentNullException">The parameter 'exporter' or 'context' is null.</exception>
1969 /// <exception cref="ArgumentException">The parameter 'ns' is either null or String.Empty.</exception>
1970 /// <exception cref="InvalidOperationException">The namespace 'ns' is not a recognized WS-Trust namespace.</exception>
1971 protected virtual void ImportSchema(WsdlExporter exporter, WsdlEndpointConversionContext context, string ns)
1973 if (exporter == null)
1975 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("exporter");
1978 if (context == null)
1980 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
1983 if (String.IsNullOrEmpty(ns))
1985 throw DiagnosticUtility.ThrowHelperArgumentNullOrEmptyString("ns");
1988 foreach (XmlSchema xmlSchema in context.WsdlPort.Service.ServiceDescription.Types.Schemas)
1990 foreach (XmlSchemaObject include in xmlSchema.Includes)
1992 XmlSchemaImport schemaImport = include as XmlSchemaImport;
1993 if ((schemaImport != null) && StringComparer.Ordinal.Equals(schemaImport.Namespace, ns))
1995 // The schema is already imported. Just return.
2001 XmlSchema schema = GetXmlSchema(exporter, ns);
2004 throw DiagnosticUtility.ThrowHelperInvalidOperation(SR.GetString(SR.ID3004, ns));
2006 XmlSchema importedSchema = null;
2007 if (context.WsdlPort.Service.ServiceDescription.Types.Schemas.Count == 0)
2009 importedSchema = new XmlSchema();
2010 context.WsdlPort.Service.ServiceDescription.Types.Schemas.Add(importedSchema);
2014 importedSchema = context.WsdlPort.Service.ServiceDescription.Types.Schemas[0];
2017 XmlSchemaImport import = new XmlSchemaImport();
2018 import.Namespace = ns;
2019 exporter.GeneratedXmlSchemas.Add(schema);
2020 importedSchema.Includes.Add(import);
2025 /// For a given namespace this method looks up the WsdlExporter to see if an XmlSchema has been cached and returns that.
2026 /// Else it loads the schema for that given namespace and returns the loaded XmlSchema.
2028 /// <param name="exporter">The WsdlExporter that exports the contract information.</param>
2029 /// <param name="ns">The namespace for which the schema is to be obtained.</param>
2030 /// <exception cref="ArgumentNullException">The parameter 'exporter' is null.</exception>
2031 /// <exception cref="ArgumentException">The parameter 'ns' is either null or String.Empty.</exception>
2032 /// <exception cref="InvalidOperationException">The namespace 'ns' is not a recognized WS-Trust namespace.</exception>
2033 static XmlSchema GetXmlSchema(WsdlExporter exporter, string ns)
2035 if (exporter == null)
2037 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("exporter");
2040 if (String.IsNullOrEmpty(ns))
2042 throw DiagnosticUtility.ThrowHelperArgumentNullOrEmptyString("ns");
2045 ICollection schemas = exporter.GeneratedXmlSchemas.Schemas(ns);
2046 if ((schemas != null) && (schemas.Count > 0))
2048 foreach (XmlSchema s in schemas)
2054 string xmlSchema = null;
2057 case WSTrustFeb2005Constants.NamespaceURI:
2058 xmlSchema = WSTrustFeb2005Constants.Schema;
2060 case WSTrust13Constants.NamespaceURI:
2061 xmlSchema = WSTrust13Constants.Schema;
2064 throw DiagnosticUtility.ThrowHelperInvalidOperation(SR.GetString(SR.ID5004, ns));
2067 return XmlSchema.Read(new StringReader(xmlSchema), null);
2071 /// During WSDL generation, the method fixes a given operation message element to refer to the
2072 /// RST and RSTR elements of the appropriate WS-Trust version.
2074 /// <param name="serviceDescription">The ServiceDescription that has the current state of the exported
2076 /// <param name="portType">The WSDL PortType whose messages are to be fixed.</param>
2077 /// <param name="context">Provides mappings from exported WSDL elements to the endpoint description.</param>
2078 /// <param name="operationName">The operation name inside the PortType.</param>
2079 /// <param name="inputMessageElement">The XmlQualifiedName of the input message element.</param>
2080 /// <param name="outputMessageElement">The XmlQualifiedName of the output message element.</param>
2081 /// <exception cref="ArgumentNullException">The parameter 'serviceDescription', 'portType', 'inputMessageType'
2082 /// or 'outputMessageType' is null.</exception>
2083 /// <exception cref="ArgumentException">The parameter 'operationName' is null or Empty.</exception>
2085 /// Trust Contract exposed by the Framework takes a System.ServiceModel.Channels.Message in and
2086 /// returns a System.ServiceModel.Channels.Message out. But Trust messages expects and RST and
2087 /// returns an RSTR/RSTRC. This method fixes the message elements with the appropriate WS-Trust
2088 /// messages specified by the XmlQualified names 'inputMessageElement' and 'outputMessageElement'.
2090 protected virtual void FixMessageElement(
2091 System.Web.Services.Description.ServiceDescription serviceDescription,
2093 WsdlEndpointConversionContext context,
2094 string operationName,
2095 XmlQualifiedName inputMessageElement,
2096 XmlQualifiedName outputMessageElement)
2098 if (serviceDescription == null)
2100 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceDescription");
2103 if (portType == null)
2105 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("portType");
2108 if (context == null)
2110 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
2113 if (String.IsNullOrEmpty(operationName))
2115 throw DiagnosticUtility.ThrowHelperArgumentNullOrEmptyString("operationName");
2118 if (inputMessageElement == null)
2120 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("inputMessageElement");
2123 if (outputMessageElement == null)
2125 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("outputMessageElement");
2128 Operation operation = null;
2129 System.Web.Services.Description.Message inputMessage = null;
2130 System.Web.Services.Description.Message outputMessage = null;
2132 foreach (Operation op in portType.Operations)
2134 if (StringComparer.Ordinal.Equals(op.Name, operationName))
2138 // Find the correspinding message in the messages collection.
2139 foreach (System.Web.Services.Description.Message message in serviceDescription.Messages)
2141 if (StringComparer.Ordinal.Equals(message.Name, op.Messages.Input.Message.Name))
2143 if (message.Parts.Count != 1)
2145 throw DiagnosticUtility.ThrowHelperInvalidOperation(
2146 SR.GetString(SR.ID3144, portType.Name, op.Name, message.Name, message.Parts.Count));
2148 inputMessage = message;
2150 else if (StringComparer.Ordinal.Equals(message.Name, op.Messages.Output.Message.Name))
2152 if (message.Parts.Count != 1)
2154 throw DiagnosticUtility.ThrowHelperInvalidOperation(
2155 SR.GetString(SR.ID3144, portType.Name, op.Name, message.Name, message.Parts.Count));
2157 outputMessage = message;
2160 if ((inputMessage != null) && (outputMessage != null))
2167 if (operation != null)
2173 if (operation == null)
2175 // This operation is missing. This might be due to another Behavior that has modified the WSDL as
2176 // well. Ignore this and return.
2180 if (inputMessage == null)
2182 throw DiagnosticUtility.ThrowHelperInvalidOperation(
2183 SR.GetString(SR.ID3149, portType.Name, portType.Namespaces, operationName));
2185 if (outputMessage == null)
2187 throw DiagnosticUtility.ThrowHelperInvalidOperation(
2188 SR.GetString(SR.ID3150, portType.Name, portType.Namespaces, operationName));
2191 inputMessage.Parts[0].Element = inputMessageElement;
2192 outputMessage.Parts[0].Element = outputMessageElement;
2193 inputMessage.Parts[0].Type = null;
2194 outputMessage.Parts[0].Type = null;