none
How do I set credentials? RRS feed

  • Question

  • I'm following a sample that shows how to set credentials and I'm trying to do the same in my code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Net;
    using WebServiceClient.InformationServiceReference;
    
    namespace WebServiceClient
    {
        public class Class1
        {
            static void Main(string[] args)
            {
              
                PartnerInfoServicePortClient pbs = new PartnerInfoServicePortClient();
                pbs.Credentials = new NetworkCredential("username", "password");                  
    
            }
        }
    }

    But the word 'Credentials' (right after pbs) isn't recognized and when holding the mouse over it I get this message:

    "WebServiceClient.InformationServiceReference.PartnerInfoServicePortClient does not contain a definition for 'Credentials' and no extension method 'Credentials' accepting a first argument of type 'WebServiceClient.InformationServiceReference.PartnerInfoServicePortClient' could be found (are you missing a using directive or assembling reference?)"

    What could be wrong? Which using directive should I add (if that's the problem)?


    • Edited by Jonas Andersson Tuesday, August 20, 2013 1:37 AM Changing sentence
    Sunday, August 18, 2013 11:39 PM

Answers

  • Hi,

    As the error said, the PartnerInfoServicePortClient which is a serviceclient does not contain a definition for the 'Credentials' but has a definition for 'ClientCredentials'.

    We can use credentials in webclient as following:

    WebClient client = new WebClient();
    client.Credentials = new NetworkCredential("username", "password");

    Or we can use the ClientCredentials as following:

    PartnerInfoServicePortClient pbs = new PartnerInfoServicePortClient();
    pbs.ClientCredentials.UserName.UserName = "username";
    pbs.ClientCredentials.UserName.Password="password";

    Best Regards,
    Amy Peng


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Tuesday, August 20, 2013 3:46 AM
    Moderator