知识大全 动态IP的Web service调用

Posted 地址

篇首语:一寸光阴一寸金,寸金难买寸光阴。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 动态IP的Web service调用相关的知识,希望对你有一定的参考价值。

动态IP的Web service调用  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

  系统架构需要使用Web service来降低耦合性 但是 现场布置的时候 WebService的地址是不固定的

  可以使用修改exe文件的对应的nfig中的设置来达到目的

  nfig文件是一个XML配置文件 其中描述了Web Service的地址 节点@ configuration/system serviceModel/client/endpoint 中的 address 属性的值就是Web Service的地址 例如

  创建一个类DynamicURL来进行Web Service地址修改操作

  class DynamicURL    using System Diagnostics;    using System Xml;    using System IO;    using System Windows Forms;    namespace TestWSDL            public class DynamicURL                    static public string LoadURL()                            string exeConfigFile = Process GetCurrentProcess() MainModule FileName + nfig ;                if (File Exists(exeConfigFile))                                    XmlDocument xmlDoc = new XmlDocument();                    xmlDoc Load(exeConfigFile);                    XmlNode xn = xmlDoc SelectSingleNode(@ configuration/system serviceModel/client/endpoint );                    if (xn != null)                                            XmlElement xe = (XmlElement)xn;                        if (xe != null)                                                    return xe GetAttribute( address );                                                                            else                                    MessageBox Show(string Format( 找不到文件 exeConfigFile));                                return string Empty;           

  static public long SaveURL(string URL)           

  string exeConfigFile = Process GetCurrentProcess() MainModule FileName + nfig ;                if (File Exists(exeConfigFile))                                    XmlDocument xmlDoc = new XmlDocument();                    xmlDoc Load(exeConfigFile);                    XmlNode xn = xmlDoc SelectSingleNode(@ configuration/system serviceModel/client/endpoint );                    if (xn != null)                                            XmlElement xe = (XmlElement)xn;                        if (xe != null)                                                    xe SetAttribute( address URL);                            xmlDoc Save(exeConfigFile);                            return ;                                                                            else                                    MessageBox Show(string Format( 找不到文件 exeConfigFile));                                return ;                       

  为了测试 建议Web Service HelloWorld 里面有方法HelloWorld 返回字符串 Hello World 拷贝HelloWorld成HelloWorld 然后将HelloWorld的返回值设置成 This is the second Hello world Web Service   以便调用的时候 可以区别两个Web Service

  在新建的窗体上添加 个按钮和 个TextBox控件

  往工程中添加服务引用 ServiceReference VS 会自动添加 上服务描述

  Form 为测试窗体

  测试窗体    using System;    using System Windows Forms;

  namespace TestWSDL            public partial class Form : Form                    public Form ()                            InitializeComponent();                this textBoxURL Text = DynamicURL LoadURL();           

  private void buttonModifyURL_Click(object sender EventArgs e)                            if ( == DynamicURL SaveURL(this textBoxURL Text))                                    MessageBox Show( 修改Web Service的URL成功 );                           

  private void buttonCallWebService_Click(object sender EventArgs e)                            this textBoxResult Text = ;                ServiceReference ServiceSoapClient client = new TestWSDL ServiceReference ServiceSoapClient();                this textBoxResult Text = client HelloWorld();                       

  测试步骤

  在IIS中为两个Web Services分别设置虚拟目录HelloWorld和HelloWorld

  运行程序 点击调用按钮查看调用结果 再将URL地址从 修改成 点击 修改Web Service地址 再调用Web Service查看结果

  两次Web Service调用结果分别为 Hello World 和 This is the second Hello world Web Service

cha138/Article/program/net/201311/12414

相关参考

知识大全 实现异步调用Web Service,防止页面超时

实现异步调用WebService,防止页面超时  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  普

知识大全 学好基本功之熟练调用 Web Service

学好基本功之熟练调用WebService  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  什么是W

知识大全 调用.NET XML Web Services返回数据集合二

调用.NETXMLWebServices返回数据集合二  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧

知识大全 在ASP.NET Atlas中调用Web Service

在ASP.NETAtlas中调用WebService  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

知识大全 使用eclipse调用.net web service

  以前我用的开发框架都是net现在换成javaEE框架和linux平台还需要一段时间的学习有时在测试工作中需要实现一些功能但是又不会用java实现怎么办呢?这里有一个方法使用net的框架开发webs

知识大全 ASP.NET 3.5核心编程之AJAX Web Service的调用

ASP.NET3.5核心编程之AJAXWebService的调用  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起

知识大全 Spring中的service之间如何调用

Spring中的service之间如何调用  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 

知识大全 使用 XML Web services 进行 Web 编程

使用XMLWebservices进行Web编程  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  X

知识大全 Android MediaPlayer播放音乐有必要使用Service来调用吗

AndroidMediaPlayer播放音乐有必要使用Service来调用吗  以下文字资料是由(本站网www.cha138.com)小编为大家搜集整理后发布的内容,让我

知识大全 使用cxf写web service的简单实例

实例步骤      第一步在myeclipse中新建一个web项目名为webservicetest并导入依赖的jar包(cxfspringa