以下代码GetAPIAddress将返回:http://localhost:2555/APITEST.asmx

using System.Web.Configuration;
using System.ServiceModel.Configuration;

   

        /// <summary>
        /// 获取Api地址
        /// 返回system.serviceModel/client/endpoint节点address属性值
        /// </summary>
        public static String GetAPIAddress
        {
            get
            {
                ClientSection clientSection = (ClientSection)WebConfigurationManager.GetSection("system.serviceModel/client");
                if (clientSection != null
                    && clientSection.Endpoints.Count > 0
                    && clientSection.Endpoints[0] != null
                    && clientSection.Endpoints[0].Address != null
                    )
                    return clientSection.Endpoints[0].Address.AbsoluteUri;
                return string.Empty;
            }
        }

Web.config配置信息:

<system.serviceModel>
   <bindings>
            <basicHttpBinding>
                <binding name="http" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="885536000" maxBufferPoolSize="524288" maxReceivedMessageSize="885536000" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="524288" maxArrayLength="524288" maxBytesPerRead="4096" maxNameTableCharCount="524288"/>
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
                        <message clientCredentialType="UserName" algorithmSuite="Default"/>
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
 
<client>
  <endpoint address="http://localhost:2555/APITEST.asmx" binding="basicHttpBinding" bindingConfiguration="XXXX" contract="Service.XXXX" name="XXXX" />
</client>
</system.serviceModel>
参考:

如何用代码方式获取Web.config中system.serviceModel/client节点的address的更多相关文章

  1. Asp.Net中的获取Web.config中设置的参数!(前后台的代码示例)

    一.Web.config中设置代码     <appSettings>         <add key="deleted" value="1" ...

  2. 获取Web.Config中节点的值

    读取webconfig里面的appSetting和connectionString <appSettings> <add key="SiteURL" value= ...

  3. web.config中配置数据库(多数据)连接的两种方式

    这是我的第一篇文章,既然是第一篇了,那就从最基础的只是说起--web.config中配置数据库连接. 网上有很多这方面的资料,但发现并没有一篇从头到位很清楚明了说完的,今天就把我的整理写在这里吧. 在 ...

  4. 在Asp.Net MVC 中如何用JS访问Web.Config中appSettings的值

    应用场景: 很多时候我们要在Web.Config中添加appSettings的键值对来标识一些全局的信息,比如:调用service的domain,跳转其他网站页面的url 等等: 那么此时就涉及到了一 ...

  5. 修改和获取web.config或app.config文件appSettings配置节中的Add里的value属性 函数

    1: /// <summary> 2: /// 修改web.config或app.config文件appSettings配置节中的Add里的value属性 3: /// </summ ...

  6. C# 获取 与 修改 web.config中的值(修改Xml文件)

    定义web.config 中 appSettings 节点 <appSettings> <add key="domainExist" value="fa ...

  7. (译)利用ASP.NET加密和解密Web.config中连接字符串

    介绍 这篇文章我将介绍如何利用ASP.NET来加密和解密Web.config中连接字符串 背景描述 在以前的博客中,我写了许多关于介绍 Asp.net, Gridview, SQL Server, A ...

  8. 利用ASP.NET加密和解密Web.config中连接字符串

    摘自:博客园 介绍 这篇文章我将介绍如何利用ASP.NET来加密和解密Web.config中连接字符串 背景描述 在以前的博客中,我写了许多关于介绍 Asp.net, Gridview, SQL Se ...

  9. 结合jquery的前后端加密解密 适用于WebApi的SQL注入过滤器 Web.config中customErrors异常信息配置 ife2018 零基础学院 day 4 ife2018 零基础学院 day 3 ife 零基础学院 day 2 ife 零基础学院 day 1 - 我为什么想学前端

    在一个正常的项目中,登录注册的密码是密文传输到后台服务端的,也就是说,首先前端js对密码做处理,随后再传递到服务端,服务端解密再加密传出到数据库里面.Dotnet已经提供了RSA算法的加解密类库,我们 ...

随机推荐

  1. UVA 1400."Ray, Pass me the dishes!" -分治+线段树区间合并(常规操作+维护端点)并输出最优的区间的左右端点-(洛谷 小白逛公园 升级版)

    "Ray, Pass me the dishes!" UVA - 1400 题意就是线段树区间子段最大和,线段树区间合并,但是这道题还要求输出最大和的子段的左右端点.要求字典序最小 ...

  2. 洛谷P1088 火星人 [STL]

    题目传送门 火星人 格式难调,题面就不放了. 分析: 这道题目不得不又让人感叹,还是$STL$大法好!!! $C++$的$algorithm$库中自带有$next\_permutation()$和$p ...

  3. Windows 消息循环(1) - 概览

    本文从消息循环是如何驱动程序的这个角度,对 Windows 消息循环进行概览性介绍. 使用 EN5 课件获得更好的阅读体验: [希沃白板5]课件分享 : <Windows培训 - 消息循环> ...

  4. centos 7 安装python3.5

    1.安装编译环境 yum groupinstall 'Development Tools' yum install zlib-devel bzip2-devel openssl-devel ncure ...

  5. 【UOJ 80】 二分图最大权匹配

    [分析] 之前打的那种KM会TLE... why??明明说n^3的啊? #include<cstdio> #include<cstdlib> #include<cstri ...

  6. 【UOJ #110】【APIO 2015】Bali Sculptures

    http://uoj.ac/problem/110 这道题subtask4和subtask5是不同的算法. 主要思想都是从高位到低位贪心确定答案. 对于subtask4,n比较小,设\(f(i,j)\ ...

  7. PHP 基础函数(二)数组的内部指针

    current($arr);  返回数组中的当前单元pos($arr);  返回数组中的当前单元key($arr);  返回数组中当前单元的键名prev($arr);  将数组中的内部指针倒回一位ne ...

  8. mysql group by 组内排序

    有数据表 comments------------------------------------------------| id | newsID | comment | theTime |---- ...

  9. 应该用H5编写APP还是用原生的呢?

    现观目前市场上的APP横行,不同行业.不同类目的APP在国内各大应用市场挤爆的满满了,那么作为一个程序员或者一个企业如何能从容的把握住制作一款实用又符合用户体验的APP呢? 自从接触APP也有四年多了 ...

  10. django safe 过滤器--不对字符串进行转义(转)

    unix下的binutils短小精悍,用胶水(俺经常成管道为胶水)紧密结合在一起释放巨大的能量.django的过滤器也学习了这个方式,每个版本的django都自带了一些builtin的filter,当 ...