0

The main question is - how to add new class object (specified by connected service) into XmlNode array using c#?

I was generating soap message by adding new objects/class into message frame, by predefined values.

Soap generation and problems:

authenticationRequest request = new authenticationRequest
            {
                pid = PID,
                authenticationProvider = new[]
                {
                    authenticationProvider.authtslidentitycard,
                    authenticationProvider.authltbank,
                    authenticationProvider.authsignatureProvider,
                    authenticationProvider.authloginpass,
                    authenticationProvider.authltgovernmentemployeecard,
                    authenticationProvider.authstork,
                    authenticationProvider.authtslidentitycard
                },
                authenticationAttribute = new[]
                {
                    authenticationAttribute.ltpersonalcode,
                    authenticationAttribute.ltcompanycode,
                },
                postbackUrl = RETURN_URL,
                customData = customData,
                Signature = new SignatureType
                {
                    SignatureValue = new SignatureValueType
                    {
                        Value = sigInBytes,
                    },
                    KeyInfo = new KeyInfoType
                    {
                        Items = new object[]
                        {
                            !!TODO!!
                        }
                    },
                    SignedInfo = new SignedInfoType
                    {
                        CanonicalizationMethod = new CanonicalizationMethodType
                        {
                            Algorithm = "http://www.w3.org/2001/10/xml-exc-c14n#",
                            Any = new XmlNode[]
                            {
                             !!TODO!!
                             At this point error occurs:
                             InclusiveNamespaces{
                                    PrefixList = "authentification"
                                }
                            },

                        },
                        SignatureMethod = new SignatureMethodType
                        {
                            Algorithm = "http://www.w3.org/2001/10/xml-exc-c14n#",
                            Any = new XmlNode[]
                            {

                            }
                        }
                    }
                },
                userInformation = new[]
                {
                    userInformation.firstName,
                    userInformation.lastName,
                    userInformation.companyName
                }
            };

And the soap looks like, with marked problems:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <authenticationRequest xmlns="http://serviceUrl/.../..">
      <pid>SomeStuff</pid>
      <serviceTarget>citizen</serviceTarget>
      <authenticationProvider>auth.tsl.identity.card</authenticationProvider>
      <authenticationProvider>auth.bank</authenticationProvider>
      <authenticationProvider>auth.signatureProvider</authenticationProvider>
      <authenticationProvider>auth.login.pass</authenticationProvider>
      <authenticationProvider>auth.government.employee.card</authenticationProvider>
      <authenticationProvider>auth.stork</authenticationProvider>
      <authenticationProvider>auth.tsl.identity.card</authenticationProvider>
      <authenticationAttribute>personal-code</authenticationAttribute>
      <authenticationAttribute>company-code</authenticationAttribute>
      <userInformation>firstName</userInformation>
      <userInformation>lastName</userInformation>
      <userInformation>companyName</userInformation>
      <postbackUrl>https://noneedtoknow.com</postbackUrl>
      <customData />
      <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
        <SignedInfo>
          <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
          {HOW TO ADD : 
          <InclusiveNamespaces xmlns="http://www.w3.org/2001/10/xml-exc-c14n#" 
                PrefixList="authentication" />
          }
          </CanonicalizationMethod>
          <SignatureMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
        </SignedInfo>
        <SignatureValue>{SOME SIGNATURE}</SignatureValue>
        <KeyInfo />
      </Signature>
    </authenticationRequest>
  </s:Body>
</s:Envelope>

So how to transform service.InclusiveNamespaces class into xmlNode ?

Karlito
  • 83
  • 5
  • Not entirely sure what you're trying to do here, but if you need to serialize a c# POCO directly to an `XmlNode` (or, more specifically, an `XmlElement`) See `XmlNodeExtensions.AsXmlElement(this T o, ...)` from [this answer](https://stackoverflow.com/a/32900890/3744182) to [How to initialize `XmlElement[]`?](https://stackoverflow.com/q/32805732/3744182) and also [this answer](https://stackoverflow.com/a/42123127/3744182) to [Populating ANY elements on a web service in C#](https://stackoverflow.com/q/42114531/3744182). – dbc Jan 29 '20 at 08:54
  • See following posting : https://stackoverflow.com/questions/46722997/saml-assertion-in-a-xml-using-c-sharp/46724392 – jdweng Jan 29 '20 at 10:01

0 Answers0