none
Setting username/password on proxy on WSHttpBinding

    Question

  • I am currently creating service references for some new web services in my application. Previously, in 2.0 I was able to create an "Add web reference". Now, in 3.5 I have to use "Add a service reference". I know there is some backwards compatibility so I *can* create a a web reference but I don't see the point as there are some advantages in using the latest service model.

    However, when creating the web service call client I cannot find how to set username/password on the proxy of the HTTP request. Here is what I got:

     

          Dim binding As New ServiceModel.WSHttpBinding
          binding.ProxyAddress = New Uri("http://myproxy:8080")
          Dim c As New VC.TrialRegistration.VCTrialRegistrationSoapClient(binding, New ServiceModel.EndpointAddress("http://www.mysite.com/wsx/Registration.asmx"))
    

    So, how do I set the username/password on the proxy? Thanks!

    • Moved by John SaundersModerator Friday, June 17, 2011 3:12 PM wcf q (From:ASMX Web Services and XML Serialization)
    Friday, June 17, 2011 10:53 AM

Answers

  • Try using the ChannelFactory to create the proxy. This exposes a credential property.

    var factory = new ChannelFactory<IService>("myendpoint");
    factory.Credentials.UserName.UserName = "";
    factory.Credentials.UserName.Password = "";
    var proxy = factory.CreateChannel();

    Also check this setting on your config file. (prevent 407 error)

    <system.net>
      <defaultProxy useDefaultCredentials="true" />
    </system.net>

    I hope this helps

     


    0g
    • Marked as answer by Yi-Lun Luo Thursday, June 23, 2011 9:26 AM
    Tuesday, June 21, 2011 9:01 PM

All replies

  • something like:

    WCFTestService.ServiceClient myService = new
                        WCFTestService.ServiceClient();
          myService.ClientCredentials.UserName.UserName = "username";
          myService.ClientCredentials.UserName.Password = p@ssw0rd;

    more details here:

    http://msdn.microsoft.com/en-us/library/ff648840.aspx

     

    and here is a related article about http://www.devatwork.nl/2007/05/wcf-username-authentication/


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Saturday, June 18, 2011 2:18 AM
    Moderator
  • After you added the service reference, take a look at your reference name. This is the namespace  that you should be using for the client reference. You can then use the ClientCredential property. For example, if the service reference name is myService, use the following:

    myService.ClientCredentials.UserName.UserName = "";
    myService.ClientCredentials.UserName.Password = ""

     


    0g
    Saturday, June 18, 2011 5:02 PM
  • I am not talking about the Credentials for the service but for the proxy. It seems you have sent me how to enter Credentials for service, Previously, in 2.0 it looked like this:

     

     

     Dim vcws As New VCWWW.Activate.VCWebService
     
     Try
     Dim pr As System.Net.WebProxy = Nothing
     If server.Connection.Proxy.ProxyType = OpenProxyClass.ProxyT.NoProxy Then
     pr = Nothing
     Else
     pr = New System.Net.WebProxy(server.Connection.Proxy.Host, server.Connection.Proxy.Port)
     If server.Connection.Proxy.UseCredentials Then
      Dim cr As New System.Net.NetworkCredential
      cr.Domain = server.Connection.Proxy.Domain
      cr.UserName = server.Connection.Proxy.UserName
      cr.Password = server.Connection.Proxy.PassWord
      pr.Credentials = cr
     End If
     End If
     vcws.Proxy = pr
    


     




    Monday, June 20, 2011 8:36 AM
  • Try using the ChannelFactory to create the proxy. This exposes a credential property.

    var factory = new ChannelFactory<IService>("myendpoint");
    factory.Credentials.UserName.UserName = "";
    factory.Credentials.UserName.Password = "";
    var proxy = factory.CreateChannel();

    Also check this setting on your config file. (prevent 407 error)

    <system.net>
      <defaultProxy useDefaultCredentials="true" />
    </system.net>

    I hope this helps

     


    0g
    • Marked as answer by Yi-Lun Luo Thursday, June 23, 2011 9:26 AM
    Tuesday, June 21, 2011 9:01 PM
  • I use .NET 3.5. And CreateChannel is not a member of factory object.

    I do not use config files but prefer to set everything programatically.

     

     

    Monday, June 27, 2011 7:57 AM