动态的设置WebSevice

朋友咨询相关问题,走了一天的弯路,呵呵。尽信书不如无书。实际上简单得很。。。

Dim DoIt As New LdWebService.LdService
DoIt.Url = "http://。。。/LdWebService/LdService.asmx"
Back = DoIt.GetConnectionString(My.Settings.ApplicationCode, My.Settings.ApplicationFlag)
也可以和方法三配合,将Url指向一个全局变量

这样全局声明,登录的时候根据用户选择的Url进行实例化,然后用就是了。
        //Reference.vb 增加一个方法,就可以很方便的实例化的时候,修改连接了
        Public Sub New(ByVal Url As String)
            MyBase.New()
            Me.Url = Url
            If (Me.IsLocalFileSystemWebService(Me.Url) = True) Then
                Me.UseDefaultCredentials = True
                Me.useDefaultCredentialsSetExplicitly = False
            Else
                Me.useDefaultCredentialsSetExplicitly = True
            End If
        End Sub
       调用方法:
         Dim DoIt As New MyWeb.LdService(" 新地址.asmx" )
方法 1 wsdl   http://localhost/myservice.asmx?wsdl  
 
得到一个代理类 .  
 
修改构造函数里面的  
  this.url   =   "Http://localhost/myservice.asmx";  
  -->   this.url   =   ConfigurationSettings.AppSettings["WebServiceUrl"];  
 
配置文件添加配置项   WebServiceUrl
方法2:可以用操作文本的形式,强行改写app.config
方法3:修改Reference.vb中的New,改写Url属性来源。
        Public Sub New()
           …………
            Me.Url = Global.MyTryIt.My.MySettings.Default.MyTryIt_MyWeb_LdService
  ………
        End Sub
方法四: http://topic.csdn.net/t/20041209/13/3629871.html 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值