作者:mobiledu2502881573 | 来源:互联网 | 2023-09-17 02:25
我编写好一个Webservice后Winfrom引用这个WebService即可使用其中的方法如果WebService的IP变了就要重新引用没什么办法能够直接改为WebS
我编写好一个Webservice 后
Winfrom 引用这个WebService 即可使用其中的方法
如果WebService 的IP变了 就要重新 引用
没什么办法能够直接改为WebService 的IP 实现动态引用
谢谢
16 个解决方案
添加Web引用. 引用名称改了. 比如MyService
就像实例化普通类的对象一样 使用他.
我只用过之直接加载在引用地址就OK 了 但是没有做过动态加载的 你看看网上的说明有的介绍的
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Services.Protocols;
using System.Configuration;
namespace Service
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name = "ServiceSoap", Namespace = "http://tempuri.org/")]
internal class ServiceProxy : SoapHttpClientProtocol
{
public ServiceProxy()
{
//this.Url = ConfigurationManager.AppSettings["Url"];
}
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/Server1", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public System.Data.DataSet Server1(string strObjType, string strObjValues)
{
object[] results = this.Invoke("Server1", new object[] {
strObjType,
strObjValues});
return ((System.Data.DataSet)(results[0]));
}
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/Server2", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public System.Data.DataSet Server2(string strObjType, string strObjValues)
{
object[] results = this.Invoke("Server2", new object[] {
strObjType,
strObjValues});
return ((System.Data.DataSet)(results[0]));
}
}
}
如果你使用反射来调用可以参考.
http://blog.csdn.net/zgke/archive/2009/03/04/3955490.aspx
调用时候用以下语句
using (ServiceProxy proxy = new ServiceProxy())
{
proxy.Url = ConfigurationManager.AppSettings["Url"];
DataSet ds = proxy.Server1("USERS", cardID);
}
看你用的2003还是2005或是2008了.
2003下面动态引用很麻烦.要通过代码生成引用代码,并编译
2005下面可直接能WEBSERVER的属性URL进行修改就行了如S_schoolManage.Url = "http://111,222,23,56/schoolmanage.asmx"
反射调用~~~
在baidu里面搜搜,有很多~~~
可以不生成程序集,直接调用WebService吗?