WinForm/C# C# 动态改变 WebServices 的 URL 地址

xinggang · 2020年11月04日 · 最后由 admin 回复于 2021年03月13日 · 149 次阅读

无法直接动态切换,每次都需要重新示例化。

private void button1_Click(object sender, EventArgs e)
{
    var url = "";
    if (checkBox1.Checked)
    {
        url = "http://app.lttc.cn/wince.asmx";
    }
    else
    {
        url = "http://10.20.71.196:8090/wince.asmx";
    }
    //这里必须重新 new 一个新对象,直接修改原来的对象不起作用 
    ws = new ServiceReference1.WinCESoapClient();
    ws.Endpoint.Address = new System.ServiceModel.EndpointAddress(url);
    MessageBox.Show(ws.GetDateTime().StringResult);
}

用到了

ningchao 回复

好的~

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册