Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to generate username token id in the request header of a soap Request. I am using asp.net with c#.
I tried to generate Username token as below:
UsernameToken userToken = new UsernameToken(Username, Password, PasswordOption.SendHashed);
I am getting username token Id output as
SecurityToken-6d139161-338c-465c-a56b-62c7414f2eda
.
But In many sample soap request usernametoken id value seen as UsernameToken-DFDA939C85F8B13ADA154211040258026.
Please update which is the proper way to pass username token id in a soap request header.

What I have tried:

Core Code is as below:
             UsernameToken userToken = new UsernameToken(Username, Password, PasswordOption.SendHashed);

                             string oRequest = @"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:enq=""https://soa.nbf.ae/Enquiry/"">
                             <soapenv:Header><wsse:Security xmlns:wsse=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"" xmlns:wsu=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"">
<wsse:UsernameToken wsu:Id="+userToken .Id+"><wsse:Username>" + Username + @"</wsse:Username><wsse:Password Type=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest"">" + strPssDigest + @"</wsse:Password><wsse:Nonce EncodingType=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"">" + strNonce + @"</wsse:Nonce><wsu:Created>" + strCreatedDate + @"</wsu:Created></wsse:UsernameToken></wsse:Security></soapenv:Header>
                             <soapenv:Body>" + Body + @"</soapenv:Body>
                                  </soapenv:Envelope>";
Posted
Updated 6-Apr-22 23:20pm
v2
Comments
Richard Deeming 7-Apr-22 5:24am    
Deleting and reposting your question will not change the answers you get.
Member 7513082 7-Apr-22 6:55am    
to get a response i just reposted the need much more precisely and shortly. please respond to the same if any one is clear on this
Chris Copeland 7-Apr-22 9:27am    
Is the request rejected if the username token doesn't begin with UsernameToken- or are you just comparing the token you're generating with others? If it works then presumably it's the correct way to do things. You'd need to consult the documentation for both the SOAP API you're using, and the C# library that you're also using to make the API calls.

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



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