private static void Serialize(SoapBody soapBody, XmlDocument document, XmlNode root) { if (soapBody == null) { throw new ArgumentNullException(nameof(soapBody)); } if (document == null) { throw new ArgumentNullException(nameof(document)); } if (root == null) { throw new ArgumentNullException(nameof(root)); } var bodyNode = document.CreateElement(Constants.XmlPrefixes.SoapEnv, Constants.XmlRootNames.SoapBody, Constants.XmlNamespaces.SoapEnvelope); if (soapBody.Request != null) { bodyNode.SetAttribute($"xmlns:{Constants.XmlPrefixes.Wsu}", Constants.XmlNamespaces.Wsu); bodyNode.SetAttribute($"{Constants.XmlPrefixes.Wsu}:Id", soapBody.Id); Serialize(soapBody.Request, document, bodyNode); } else if (soapBody.Content != null) { var nodeCopy = document.ImportNode(soapBody.Content, true); bodyNode.AppendChild(nodeCopy); } root.AppendChild(bodyNode); }
public SoapEnvelope Build() { CheckInit(); var samlAssertionId = GenerateId("assertion"); var requestId = GenerateId("request"); var bodyId = GenerateId("id"); var timeStampId = GenerateId("TS"); var x509Id = GenerateId("X509"); var ssin = GetSsin(_x509Certificate.Subject); if (string.IsNullOrWhiteSpace(ssin)) { throw new EhealthException(Constants.ErrorCodes.NoSerialNumber); } var identitySubject = ParseSubject(_x509Certificate.Subject); var issuerSubject = ParseSubject(_x509Certificate.Issuer); _samlAttributes.Add(new SamlAttribute(Constants.EhealthStsNames.SsinCertHolderAttributeName, Constants.EhealthStsNames.SsinAttributeNamespace, ssin)); _samlAttributes.Add(new SamlAttribute(Constants.EhealthStsNames.SsinAttributeName, Constants.EhealthStsNames.SsinAttributeNamespace, ssin)); _samlAttributeDesignators.Add(new SamlAttributeDesignator(Constants.EhealthStsNames.SsinCertHolderAttributeName, Constants.EhealthStsNames.SsinAttributeNamespace)); _samlAttributeDesignators.Add(new SamlAttributeDesignator(Constants.EhealthStsNames.SsinAttributeName, Constants.EhealthStsNames.SsinAttributeNamespace)); var issueInstant = DateTime.Now; var samlNameIdentifier = new SamlNameIdentifier( Constants.EhealthStsNames.NameIdentifierFormat, issuerSubject, identitySubject); var samlSubject = new SamlSubject(samlNameIdentifier); var samlConditions = new SamlConditions(issueInstant); var samlAttributeStatement = new SamlAttributeStatement(samlSubject, _samlAttributes); var samlAssertion = new SamlAssertion(samlAssertionId, issueInstant, identitySubject, samlConditions, samlAttributeStatement); var subjectConfirmationData = new SamlSubjectConfirmationData(samlAssertion); var subjectConfirmation = new SamlSubjectConfirmation(Constants.EhealthStsNames.SubjectConfirmationMethod, _x509Certificate, subjectConfirmationData); var samlSubjectO = new SamlSubject(samlNameIdentifier, subjectConfirmation); var samlAttributeQuery = new SamlAttributeQuery(samlSubjectO, _samlAttributeDesignators); var samlRequest = new SamlRequest(requestId, samlAttributeQuery); var body = new SoapBody(samlRequest, bodyId); var soapSecurity = new SoapSecurity(DateTime.UtcNow, timeStampId, x509Id, _x509Certificate); var header = new SoapHeader(soapSecurity); var soapEnvelope = new SoapEnvelope(header, body); return(soapEnvelope); }
public XmlDocument Serialize <T>(T request, XmlElement assertionNode) where T : RequestType { if (request == null) { throw new ArgumentNullException(nameof(request)); } var serialzer = new XmlSerializer(typeof(T)); string xml; using (var strW = new StringWriter()) { using (var writer = XmlWriter.Create(strW)) { serialzer.Serialize(writer, request); xml = strW.ToString(); } } var doc = new XmlDocument(); doc.LoadXml(xml); var soapBody = new SoapBody(doc.DocumentElement); SoapSecurity soapSecurity = null; if (assertionNode != null) { soapSecurity = new SoapSecurity(assertionNode); } var soapHeader = new SoapHeader(soapSecurity); var soapEnvelope = new SoapEnvelope(soapHeader, soapBody); var serializer = new SoapMessageSerializer(); return(serializer.Serialize(soapEnvelope)); }
/// <summary> /// Initializes a new instance of the SoapEnvelope class. /// </summary> /// <param name="body">The body of the soap message</param> public SoapEnvelope(SoapBody body) { this.header = new WsdHeader(); this.body = body; }
/// <summary> /// Initializes a new instance of the SoapEnvelope class. /// </summary> /// <param name="messageVersion">The version of the soap message</param> /// <param name="header">The header of the soap message</param> /// <param name="body">The body of the soap message</param> public SoapEnvelope(SoapMessageVersion messageVersion, SoapHeader header, SoapBody body) { this.messageVersion = messageVersion; this.header = header; this.body = body; }
public SoapEnvelope(SoapHeader header, SoapBody body) { Header = header; Body = body; }