C# 非动态更新Webservice的服务地址

     Webservice服务比较固定,至少有些服务比较固定,而且集中,这个时候谁也不喜欢动态的来来往往,这个时候只要修改下Web References文件夹下的Reference.cs,指定this.Url = “读取外部文件”,给个具体的代码吧

 

// 获取外部TXT文件中的webservice地址
public   static   string  GetUrl()
        {
            
string  _CodeBase  =  System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
            _CodeBase 
=  _CodeBase.Substring( 8 , _CodeBase.Length  -   8 );     //  8是 file: //  的长度
             string [] arrSection  =  _CodeBase.Split( new   char [] {  ' / '  });
            
string  _FolderPath  =   "" ;
            
for  ( int  i  =   0 ; i  <  arrSection.Length  -   1 ; i ++ )
            {
                _FolderPath 
+=  arrSection[i]  +   " / " ;
            }

            
string  fileaddress  =  _FolderPath  +   @" \WorkFlowAddress.txt " ;
            
if  ( ! File.Exists(fileaddress))
                File.Create(fileaddress);
            StreamReader sr 
=   new  StreamReader(fileaddress);
            
string  str  =  sr.ReadToEnd().Trim();
            sr.Close();
            
return  str;
        }
// 修改this.Url,其他的都不重要了,不管它们了
public  FuctionForFlow() {

            
this .Url  =  GetUrlClass.GetUrl();
                
// " http://192.168.2.16/SuperFormWS/WorkFlow/FuctionForFlow.asmx ";
                
// global::EformWorkflow.Properties.Settings.Default.EformWorkflow_EformWeb_FuctionForFlow;
             if  (( this .IsLocalFileSystemWebService( this .Url)  ==   true )) {
                
this .UseDefaultCredentials  =   true ;
                
this .useDefaultCredentialsSetExplicitly  =   false ;
            }
            
else  {
                
this .useDefaultCredentialsSetExplicitly  =   true ;
            }
        }

转载于:https://www.cnblogs.com/viki117/archive/2008/09/02/1282093.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值