Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8728181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:34:28+00:00 2026-06-13T08:34:28+00:00

I have an asmx web service and a test console app. I have added

  • 0

I have an asmx web service and a test console app. I have added web service reference to the console app and calling it like this

Employee.Employee e = new TestService.Employee.Employee();
e.SomeMethod();

On every web service call there is a validation check which looks like this

    private bool IsUserNameTokenPresent()
    {
        //Get current SOAP context
        SoapContext ctxt = RequestSoapContext.Current;
        UsernameToken user = null;
        if (ctxt == null)
        {
            //This request is using a different protocol other than SOAP.
            return false;
        }

        //Iterate through all Security tokens
        foreach(SecurityToken tok in ctxt.Security.Tokens)
        {
            if (tok is UsernameToken)
            {
                user = (UsernameToken)tok;

            }
        }
        if (user == null)
            return false;

        return true;
    }

Question: How do I pass the Security Token so that I can test this service. Its always null.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:34:29+00:00Added an answer on June 13, 2026 at 8:34 am

    Finally found the answer for this. I had to create my own SOAP header manually and pass it with the request. Here is some code. I had to create Nonce dynamically for every call, I will post it here if someone wants the code for that.

                XmlDocument doc = new XmlDocument();
    
                doc.InnerXml = @"<?xml version='1.0' encoding='utf-8'?>
                                    <soap:Envelope 
                                    xmlns:wsu='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd' 
                                    xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' 
                                    xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'>
                                    <soap:Header>
                                    <wsse:Security soap:mustUnderstand='1'>
                                    <wsse:UsernameToken wsu:Id='uuid_faf0159a-6b13-4139-a6da-cb7b4100c10c'>
                                    <wsse:Username>UserID</wsse:Username>
                                    <wsse:Password>Pass</wsse:Password>
                                    <wsse:Nonce>" + nonce + @"</wsse:Nonce>
                                    <wsu:Created>" + date + @"</wsu:Created>
                                    </wsse:UsernameToken>
                                    </wsse:Security>
                                    </soap:Header>
                                    <soap:Body>
                                    <FindBySelfId>
                                    <specification>
                                    <LastName>" + lastname + @"</LastName>
                                    <FirstName>" + firstname + @"</FirstName>
                                    <DateOfBirth>" + dob + @"</DateOfBirth>
                                    <HomeZipCode>" + zip + @"</HomeZipCode>
                                    <SSN4>" + ssn + @"</SSN4>
                                    </specification>
                                    </FindBySelfId  >
                                    </soap:Body>
                                    </soap:Envelope>";
    
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost/Employee/employee.asmx");
    
                req.Headers.Add("SOAPAction", "https://<Namespace here>");
    
                req.ContentType = "text/xml;charset=\"utf-8\"";
                req.Accept = "text/xml";
    
                req.Method = "POST";
                Stream stm = req.GetRequestStream();
                doc.Save(stm);
                stm.Close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have a simple wcf service like this, with a test method which
I have a windows application where i added a web service to sharepoint Lists.asmx.
I have a asmx web service running on a test server that has anonymous
I have an asmx web service that should only be allowed to respond to
Im trying to create an ASMX Web Service in Visual Web Developer.I have successfully
I have a custom desktop application which invokes an ASMX web service. The Service
I have a .NET web service (using asmx...have not upgraded to WCF yet) that
I have a web service that contains 2 asmx files (public.asmx and private.asmx). On
I have a web service contains a web method with the url http://localhost/Service1.asmx?op=AddNumbers .
Can't seem to figure this one out. I have a web service defined as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.