locked
Using The WSDL Tool And Secure Service RRS feed

  • Question

  • User564952083 posted

    I had originally posted this in the wrong area.  I finally figured the initial answer out on my own so I thought I would follow the suggestion of posting it here.  I am certain some of  the users here can fill in the finer details for me.  I'll put my oringal post and then I will put what I feel is an "initial answer".  I say "initial answer" because yes it works but I don't think it is the best way to do it.

    First my original post:

    I have used the WSDL tool before to create a proxy class for a web service that is not hosted on IIS.  I now have to use one that requires a user name and password in the SOAP request properties.  This authentication is not part of the web methods, but part of accessing the URL for the methods.

    My question is how do I supply that information?

    Tuesday, August 27, 2013 3:10 PM

Answers

  • User564952083 posted

    After some vacation and asking a friend, I finally figured it out.  Like anything it seems so easy.

    O.K.  In the proxy class that the wsdl tool generates I saw I could access this.Credentials.  It is an object that expects something that implements System.Net.ICredentials.

    So I created a new class which implemented this ICredentials interface which I will call ProxyCreds.  I left its constructor empty and used Implement Interface Explicitly to create the methods I needed.  Turns out there is only one.  This method takes a URI and a string as parameters, but I did not use them.  I might if I can find where to set those globally in the proxy class, but for now, setting the username and password in this one method will suffice.

    using System;
    using System.Net;
    
    /// <summary>
    /// Class to provide credentials 
    /// for the web service
    /// </summary>
    public class ProxyCreds : ICredentials
    {
        public ProxyCreds()
        {
        }
    
        NetworkCredential ICredentials.GetCredential(Uri uri, string authType)
        {
            //TODO Set the user and password
            return new NetworkCredential("userName", "passWord");
        }
    }

    In the constructor for the proxy class I create a new instance of my class (ProxyCreds) that implements ICredentials.  Then I set this.Credentials equal to that instance.

    In my case it worked.  I'm sure there is a better way to do this, but it is a start.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 27, 2013 3:13 PM