一个DLL中封装了提供WEBSERVICE服务的服务器IP,可现在才知道服务器的IP不明确,怎么才能动态的在配置文件WEB.config中动态绑定呢

解决方案 »

  1.   


    using System.Net;

    Dns.Resolve(Dns.GetHostName()).AddressList[i](i为第几个网络连接是外网,就是几)
    获得网站服务器的IP!
      

  2.   

    具体情况:我用HttpModule做了个截取筛选器(MyModule.dll),作用是当访问重要页面前必须调用一个WebService,这个WebServic根据2个参数返回一个User,现在的问题是MyModule.dll中引用了发布WebService的服务器IP,可这个IP现在不确定,可能会变,我觉得说应该可以在配置文件中写成自动捕获的,可我查了半天网不知从何下手??? 代码如下:using System;
    using System.Web;
    using System.Security.Principal;
    using System.Diagnostics;namespace MyModule
    {
    /// <summary>
    /// Class1 的摘要说明。
    /// </summary>
    public class SyncModule : IHttpModule  //必须继承IHttpModule接口
    {
    private HttpApplication httpApp; public void Init(HttpApplication httpApp)
    {
    this.httpApp = httpApp;
    httpApp.AuthenticateRequest  += new EventHandler(OnAuthentication);//在Init中注册

    } void OnAuthentication(object sender, EventArgs a)//OnAuthentication是在将要验证时自动引发
    {
    HttpApplication application = (HttpApplication)sender;
    HttpResponse response = application.Context.Response;
    WebReference.UserServiceBinding binding = new WebReference.UserServiceBinding();//构造代理类
    WebReference.User user=binding.Authenticate(application.Request.Params.Get("token"),application.Request.UserHostAddress);//根据字符串token和请求者的IP返回一个User对象
               
    if (user==null)
    {
    string failPage=System.Configuration .ConfigurationSettings .AppSettings ["failPage"];//如果对象不存在,就导航到指定错误页面,具体页面在用户的WebConfig中配置
    response.Redirect("failPage",true);
    }
    }
    public void Dispose()
    {} }
    }
      

  3.   

    申请一下域名,比如www.mywebservice.com然后,服务器IP换了后更新域名指向就可以了,程序不用运.然后你的程序里使用域名来连接.
      

  4.   

    把webservic的访问url配到web.config中WebReference.UserServiceBinding binding = new WebReference.UserServiceBinding();//构造代理类
    binding.Url=System.Configuration.ConfigurationSettings.AppSettings["MyWebServiceUrl"];
    ....
      

  5.   

    那MyWebServiceUrl是KEY,但VALUE怎么写呢
      

  6.   

    http://10.199.1.1/test/myService.asmx这样的