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;
}
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;
}
}
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;
}
}