c#靜態轉變webservice的url拜訪地址。本站提示廣大學習愛好者:(c#靜態轉變webservice的url拜訪地址)文章只能為提供參考,不一定能成為您想要的結果。以下是c#靜態轉變webservice的url拜訪地址正文
1、添加一個App.config設置裝備擺設文件。
2、設置裝備擺設辦事http://Lenovo-PC:80/EvisaWS/WharfService?wsdl,那末在下面的文件中就會主動生成辦事的設置裝備擺設:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WharfWSBeanBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://Lenovo-PC:80/EvisaWS/WharfService"
binding="basicHttpBinding" bindingConfiguration="WharfWSBeanBinding"
contract="WharfService.WharfWSBean" name="WharfService" />
</client>
</system.serviceModel>
</configuration>
3、靜態添加新的地址,前面的?wsdl沒有也能夠:
WharfWSBeanClient c = new WharfWSBeanClient("WharfService", "新的地址例如:http://192.168.1.194/EvisaWS/WharfService?wsdl");
4、新辦事器的地址可以寄存到注冊表或許情況變量外面,上面是新寄存到注冊表,然後再寄存到情況變量裡,拜訪的時刻先從情況變量外面獲得:
4.1 存到注冊表:
RegistryKey key = Registry.LocalMachine.CreateSubKey(@"Software\Client");
key.SetValue("ip", "192.168.1.1");
4.2 從注冊表獲得值:
String ip =Environment.GetEnvironmentVariable("myconfigip");
if (ip == null || ip.Equals(""))
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Client");
ip = key.GetValue("myip") as string;
Environment.SetEnvironmentVariable("myconfigip", ip);
}
下面是先從情況變量外面取,假如沒有則從注冊表取,以後又寄存到情況變量裡,今後在過程內拜訪時直接從情況變量外面取便可以了。