WCF服务用户名密码访问
2017-07-10 10:04
211 查看
有2种方式,
第一直接在程序中指定用户名密码,配置调用
Web.Config配置文件中添加对用户名和密码的标签访问
第一直接在程序中指定用户名密码,配置调用
private void BtnSearch_Click(object sender, EventArgs e) { try { var client = new TicketListService.TicketListServicePortTypeClient(); client.ClientCredentials.UserName.UserName = ConfigurationManager.AppSettings["UserName"]; client.ClientCredentials.UserName.Password = ConfigurationManager.AppSettings["Password"]; if (!string.IsNullOrEmpty(txtParam.Text.Trim())) { string paramjson = txtParam.Text.Trim(); string datajson = client.queryTicketAllList(paramjson); richTextBox1.Text = ConvertJsonString(datajson); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
Web.Config配置文件中添加对用户名和密码的标签访问
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> </configSections> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> </startup> <appSettings> <add key="UserName" value="admin"/> <add key="Password" value="123"/> </appSettings> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="ITicketListServiceHttpBinding" > <security mode="TransportCredentialOnly" > <transport clientCredentialType="Basic"/> <message clientCredentialType="UserName"/> </security> </binding> </basicHttpBinding> </bindings> <client> <endpoint address="http://10.8.0.126/dxp/remote/execut" binding="basicHttpBinding" bindingConfiguration="ITicketListServiceHttpBinding" contract="TicketListService.ITicketListServicePortType" name="ITicketListServiceHttpPort" /> </client> </system.serviceModel> </configuration>
相关文章推荐
- WCF服务安全控制之netTcpBinding的用户名密码验证
- 用https访问GIT服务时避免输入用户名、密码的方法
- WCF服务安全控制之netTcpBinding的用户名密码验证【转】
- WinXP下用用户名和密码访问Ubuntu共享文件------Samba服务!
- 【Misc】OAuth(解决)第三方访问私密服务(不暴露用户名/密码)
- WCF服务安全控制之netTcpBinding的用户名密码验证
- WampServer PHP服务配置方法(允许外部访问、phpmyadmin设置为输入用户名密码才可登录等)
- win7通过samba服务访问linux提示用户名和密码错误
- “windows 2003域用户在客户端用域服务器IP和域名称访问IIS提示输入用户名密码”解决办法
- apache的认证安全配置,访问资源时,弹出登陆框需要用户名密码
- WCF 安全之自定义的用户名/密码身份验证
- WCF基于用户名和密码安全成功测试
- [转贴][WCF Security] 4. 用户名/密码身份验证
- WCF 安全之自定义的用户名/密码身份验证
- [转]如何更改访问局域网共享用户名和密码
- 在Windows Mobile 6上调用WCF访问PC上的服务(转)
- IIS访问出错[要求输入用户名密码]的解决方案
- 带用户名密码---远程访问另一台主机中共享文件夹中文件
- [转载]怎样设置用不同的用户名和密码访问网上邻居的其他电脑?
- WCF的用户名密码认证