一.WCF入门 1. 新建立空白解决方案,并在解决方案中新建项目,项目类型为:WCF服务应用程序,删除系统生成的两个文件IService1.cs与Service1.svc, 添加自定义的WCF[服务文件]User.svc.建立完成后如下图所示: 2.在IUser.cs中添加方法ShowName接口和在User.svc中时间方法,如图: using System; using System.Collections.Generic; using System.Linq; using System.R
//动态调用wcf方法 string url = "http://localhost:54379/ServiceWCF.svc"; IDoubleService proxy = WcfInvokeFactory.CreateServiceByUrl<IDoubleService>(url); int result = proxy.Add(1, 3); //wcf WCF服务工厂创建方法 public class WcfInvokeFactory {
动态调用WCF服务,只需要提供*.svc地址, 1:命名空间: using System.ServiceModel.Channels;using System.ServiceModel; 2:创建访问类InvokeContext public class InvokeContext { #region Wcf服务工厂 public static T CreateWCFServiceByURL<T>(string url) { return
1.url:http://localhost:8002/名称.svc/basic(.svc结尾) 2.需要引用的命名空间System.ServiceModel 3.调用代码: public class InvokeContext { #region Wcf服务工厂 public static T CreateWCFServiceByURL<T>(string url) { return CreateWCFServiceByURL<T>(url, "basichttpbin
很多时候,服务地址都不止一个的,这个时候就要动态去配置地址.配置Web.config,很麻烦 下面就看看怎样实现动态调用WCF. 首先看看动态创建服务对象的代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ServiceModel; using System.ServiceModel.Channels; /// <summary> /// 动
很多时候,服务地址都不止一个的,这个时候就要动态去配置地址.配置Web.config,很麻烦 下面就看看怎样实现动态调用WCF. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ServiceModel; using System.ServiceModel.Channels; /// <summary> /// 动态调用WCF的工具类库 /// &
最近经常用到C#动态调用类库,简单的做下记录方便以后查询. 使用下面的几行代码就可以简单实现DLL类库的调用了 using System.Reflection; // 引入该命名空间 // 获取rocky.dll的文件路径 Assembly ass = Assembly.LoadFrom("./_lib/rocky.dll"); // 获取该dll中命名空间RockyNameSpace中Study类 Type type = ass.GetType("RockyNameSpac