在代码中定义Web服务URL [英] Defining Web Service URL within Code

查看:63
本文介绍了在代码中定义Web服务URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在寻找有关如何通过代码定义Web服务URL的建议.

Looking for some advice on how to define a web service URL via code..

我正在使用VS2013(专业版),当我在VS2013中手动添加时,可以成功连接到Web服务.现在,我想允许一个UI,以便用户可以根据需要更改URL.更改 在用户界面中,以便正确刷新引用的网址?

I'm using VS2013 (Professional) and can successfully connect to a web service when I added manually within VS2013.  Now I would like to allow a UI so that a user could change the URL as needed.  Is there a way to do validation when changing the within UI so that the referenced url is properly refreshed?

谢谢..

推荐答案

正在寻找有关如何通过代码定义Web服务URL的建议.

Looking for some advice on how to define a web service URL via code..

我正在使用VS2013(专业版),当我在VS2013中手动添加时,可以成功连接到Web服务.现在,我想允许一个UI,以便用户可以根据需要更改URL.更改 在用户界面中,以便正确刷新引用的网址?

I'm using VS2013 (Professional) and can successfully connect to a web service when I added manually within VS2013.  Now I would like to allow a UI so that a user could change the URL as needed.  Is there a way to do validation when changing the within UI so that the referenced url is properly refreshed?

谢谢..

您可以设置一个包含事件和所有其他内容的课程...但是...

You could set up a class with an event and all that ... but ...

您知道什么时候允许他们更改它-毕竟是您的程序.您可以调整变量的范围,以便所需的所有内容都可以访问该变量,我认为这是最简单的方法.当您的用户单击以更改URL时,请验证诸如是否 字符串是否为null或空格,无论字符串是否以http://或https://开头.

You know when you're allowing them to change it - it's your program after all. You might scope the variable so that it's accessible to everything needed, I think that's the easiest way. When your users click to change the URL, validate things like whether or not the string is null or white space, whether or not the string starts with http:// or https://, things like that.

您甚至可以使用WebRequest并捕获异常.将超时时间设置得较低一些(例如10000毫秒),然后在更改URL时对其进行测试.

You might even use a WebRequest and trap for exceptions. Set the timeout somewhat low (like 10000 milliseconds) then test it when they change the URL.


这篇关于在代码中定义Web服务URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆