Connect with WCF to a WebService authenticated with username/password

前端 未结 3 1864
不知归路
不知归路 2021-01-31 10:53

I created a proxy of a Web Service with Visual Studio 2008, and it created for me the following entry in the app.config:


        <         


        
3条回答
  •  佛祖请我去吃肉
    2021-01-31 11:32

    I post here the solution for future readers:

    
        
          
            
              
              
                
              
            
          
        
        
          
          
    
        
      
    

    In the end I could use the default basicHttpBinding. The only difference from the code posted in the question is the security node.

    Also note the mode="TransportCredentialOnly" option, this allows you to send username/password using http instead of https. This is necessary for testing environments as the one I'm using. Later on obviously you'll prefer https to send your credentials.

    Afterwards in code you'll enter your username/password:

    var ws = new ***.MyHandlerClient("MyHandler");
    ws.ClientCredentials.UserName.UserName = "myUsername";
    ws.ClientCredentials.UserName.Password = "myPassword";
    var result = ws.executeMyMethod();
    

提交回复
热议问题