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 5938295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:39:53+00:00 2026-05-22T15:39:53+00:00

I have a WPF application that has just one button. When the button is

  • 0

I have a WPF application that has just one button. When the button is clicked, all it does is open the service. Here is the code:

 private void button1_Click(object sender, RoutedEventArgs e)
    {
        ServiceReference1.TestServiceClient c = new ServiceReference1.TestServiceClient();

        XDocument doc = XDocument.Load(@"c:\Test\Test.xml");

        c.ClientCredentials.UserName.UserName = doc.Root.Element("Credentials").Attribute("username").Value;
        c.ClientCredentials.UserName.Password = doc.Root.Element("Credentials").Attribute("password").Value;

        try
        {
            c.Open();
        }
        catch (Exception ex)
        {

        }
    }

As you can see from above, I am reading the username and password from a Credentials node in an xml file to validate the client. Is it proper to have it located here, because originally, I had it defined in my Validate method:

 public override void Validate(string userName, string password)
    {

       // XDocument doc = XDocument.Load(@"c:\Test\Test.xml");

       // userName = doc.Root.Element("Credentials").Attribute("username").Value;
      //  password = doc.Root.Element("Credentials").Attribute("password").Value;


        if (string.IsNullOrEmpty(userName))
            throw new ArgumentNullException("userName");
        if (string.IsNullOrEmpty(password))
            throw new ArgumentNullException("password");

        // check if the user is not test
        if (userName != "test" || password != "test")
            throw new FaultException("Username and Password Failed");
    }

But the problem with the above is that whatever I pass into c.ClientCredentials.UserName.UserName and c.ClientCredentials.UserName.Password gets overriden when it reaches the Validate method. For example, in my button click, if I just have:

c.ClientCredentials.UserName.UserName = "test1";
c.ClientCredentials.UserName.Password = "test1";

The above should fail, but when it goes into the Validate method where I read the xml file that has the username and password attribute as test and test, it will pass.

As a side note, I noticed that my Validate method gets called, but I can’t seem to step into. The debugger symbols don’t get loaded.

  • 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-05-22T15:39:54+00:00Added an answer on May 22, 2026 at 3:39 pm

    you are overwriting the parameter with your read

     public override void Validate(string suppliedUserName, string suppliedPassword){
         // ...
         string validUserName = doc.Root.Element("Credentials").Attribute("username").Value;
         string validPassword = doc.Root.Element("Credentials").Attribute("password").Value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF application that has a variable x which is an instance
I have a WPF application with form that has a textbox named txtStatusWindow. I
I have a WPF application that runs fine under XP as an administrator. When
I have written a WPF application that I want to port to Silverlight 2.
I have a simple message box in a WPF application that is launched as
I have a WPF application in VS 2008 with some web service references. For
I have a WPF application with a form that, when started, invokes a custom
I have a simple WPF window that has 12 buttons on it. I want
So I have several comboboxes in my WPF application that don't change the selection
In a MVVM WPF application, I have a master-detail View that is used to

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.