以下代码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. c++ getline()

    #include <iostream>#include <string> int main (){ std::string name; std::cout << & ...

  2. LongAdder & AtomicInteger

    JDK8 推荐  LongAdder替代 AtomicInteger, AtomicInteger内部是实现使用 (网友使用jad反编译源码 参考 http://ifeve.com/enhanced- ...

  3. RxSwift 系列(三)

    RxSwift 系列(三) -- Combination Operators 前言 本篇文章将要学习如何将多个Observables组合成一个Observable.Combination Operat ...

  4. Hibernate 对象的生命周期及CRUD操作

    对象状态及生命周期 1.Transient(瞬时状态):new的对象为瞬时态 session中没有数据,数据库中没有数据. 2.Persistent(持久状态):被session管理的对象为持久状态, ...

  5. 【BZOJ 2054】 2054: 疯狂的馒头 (并查集特技)

    Input 第一行四个正整数N,M,p,q Output 一共输出N行,第i行表示第i个馒头的最终颜色(如果最终颜色是白色就输出0). Sample Input 4 3 2 4 Sample Outp ...

  6. 「Luogu4321」随机游走

    「Luogu4321」随机游走 题目描述 有一张 \(n\) 个点 \(m\) 条边的无向图,\(Q\) 组询问,每次询问给出一个出发点和一个点集 \(S\) ,求从出发点出发随机游走走遍这个点集的期 ...

  7. [Codeforces #201] Tutorial

    Link: 传送门 代码量很少的一套思维题 A: 试一试发现最后状态一定是所有$min,max$间$gcd$的倍数 直接判断数量的奇偶性即可 #include <bits/stdc++.h> ...

  8. [HEOI2013]SAO

    题目大意: 一个有向无环图上有n个结点, 现在告诉你n-1个条件(x,y),表示x和y的先后关系. 问原图共有几种可能的拓扑序? 思路: 树形DP. f[i][j]表示对于第i个结点,有j个点在它前面 ...

  9. [转]Android学习:EditText的使用方法

        EditText是在Android开发中经常被使用到的控件,主要用来获取用户的输入内容.   1.EditText常用属性   EditText继承自TextView,所以EditText也拥 ...

  10. Ubuntu中升极下载4.2内核

    http://tech.hexun.com/2015-09-11/179027013.html 从这段话中所表达出的意思可以了解,Linux Kernel 4.3版本已经开始进行,Linus Torv ...