• WCF服务用户名密码访问


    有2种方式,

    第一直接在程序中指定用户名密码,配置调用

          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>
  • 相关阅读:
    一个很简单的脑筋急转弯问题
    DataGrid PCV排序学习
    VS2010 出现打开关联文档错误的解决方案
    JS 简繁体互转代码
    js 常用正则表达式表单验证代码
    【转】自然语言处理(NLP)网上资源整理
    声卡编程讲解
    视频会议1
    转 语音处理资源
    编译WebRTC
  • 原文地址:https://www.cnblogs.com/yisheng/p/7144456.html
Copyright © 2020-2023  润新知