c# 动态调用WCF方法笔记!
string
url =
"http://localhost:54379/ServiceWCF.svc"
;
IDoubleService proxy = WcfInvokeFactory.CreateServiceByUrl<IDoubleService>(url);
int
result = proxy.Add(1, 3);
WCF服务工厂
创建方法public
class
WcfInvokeFactory
{
#region WCF服务工厂
public
static
T CreateServiceByUrl<T>(
string
url)
{
return
CreateServiceByUrl<T>(url,
"basicHttpBinding"
);
}
public
static
T CreateServiceByUrl<T>(
string
url,
string
bing)
{
try
{
if
(
string
.IsNullOrEmpty(url))
throw
new
NotSupportedException(
"This url is not Null or Empty!"
);
EndpointAddress address =
new
EndpointAddress(url);
Binding binding = CreateBinding(bing);
ChannelFactory<T> factory =
new
ChannelFactory<T>(binding, address);
return
factory.CreateChannel();
}
catch
(Exception ex)
{
throw
new
Exception(
"创建服务工厂出现异常."
);
}
}
#endregion
#region 创建传输协议
/// <summary>
/// 创建传输协议
/// </summary>
/// <param name="binding">传输协议名称</param>
/// <returns></returns>
private
static
Binding CreateBinding(
string
binding)
{
Binding bindinginstance =
null
;
if
(binding.ToLower() ==
"basichttpbinding"
)
{
BasicHttpBinding ws =
new
BasicHttpBinding();
ws.MaxBufferSize = 2147483647;
ws.MaxBufferPoolSize = 2147483647;
ws.MaxReceivedMessageSize = 2147483647;
ws.ReaderQuotas.MaxStringContentLength = 2147483647;
ws.CloseTimeout =
new
TimeSpan(0, 30, 0);
ws.OpenTimeout =
new
TimeSpan(0, 30, 0);
ws.ReceiveTimeout =
new
TimeSpan(0, 30, 0);
ws.SendTimeout =
new
TimeSpan(0, 30, 0);
bindinginstance = ws;
}
else
if
(binding.ToLower() ==
"nettcpbinding"
)
{
NetTcpBinding ws =
new
NetTcpBinding();
ws.MaxReceivedMessageSize = 65535000;
ws.Security.Mode = SecurityMode.None;
bindinginstance = ws;
}
else
if
(binding.ToLower() ==
"wshttpbinding"
)
{
WSHttpBinding ws =
new
WSHttpBinding(SecurityMode.None);
ws.MaxReceivedMessageSize = 65535000;
ws.Security.Message.ClientCredentialType = System.ServiceModel.MessageCredentialType.Windows;
ws.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows;
bindinginstance = ws;
}
return
bindinginstance;
}
#endregion
}
c# 动态调用WCF方法笔记!的更多相关文章
- 动态调用WCF
最近在做的一个项目中需要动态调用WCF地址,因为有很多终端服务器,而每台终端服务器上都部署一个WCF服务,中央服务器需要不定时调用其中某个或者多个WCF服务执行相关操作,因此添加引用及配置文件配置的方 ...
- 创建一个简单的WCF程序2——手动开启/关闭WCF服务与动态调用WCF地址
一.创建WCF服务器 1.创建WCF服务器的窗体应用程序 打开VS2010,选择文件→新建→项目菜单项,在打开的新建项目对话框中,依次选择Visual C#→Windows→Windows窗体应用程序 ...
- C#动态调用WCF接口,两种方式任你选。
写在前面 接触WCF还是它在最初诞生之处,一个分布式应用的巨作. 从开始接触到现在断断续续,真正使用的项目少之又少,更谈不上深入WCF内部实现机制和原理去研究,最近自己做一个项目时用到了WCF. 从这 ...
- 动态调用WCF服务
动态调用WCF服务,只需要提供*.svc地址, 1:命名空间: using System.ServiceModel.Channels;using System.ServiceModel; 2:创建访问 ...
- C#动态调用WCF接口
C#动态调用WCF接口 写在前面 接触WCF还是它在最初诞生之处,一个分布式应用的巨作. 从开始接触到现在断断续续,真正使用的项目少之又少,更谈不上深入WCF内部实现机制和原理去研究,最近自己做一个项 ...
- Qt 调用 Java 方法笔记
Qt 调用 Java 方法笔记 假设遇到相似的错误: error: undefined reference to '_jstring* QAndroidJniObject::callStaticMet ...
- 动态调用wcf接口服务
1.url:http://localhost:8002/名称.svc/basic(.svc结尾) 2.需要引用的命名空间System.ServiceModel 3.调用代码: public class ...
- POST调用WCF方法-项目实践
做即时通信项目时,需要与OA系统对接接口,主要目标是实现在OA里进行一项事项,通过调用我们的接口,即时通知过来,并弹出消息框提示一下.我们的即时通信使用的WCF服务进行通信,在客户端调用通信时,用的就 ...
- js 动态调用字符串方法并传入对应参数
在项目应用中,经常会需要根据业务数据需要动态去拼凑字符串,然后将字符串作为js代码进行执行. js提供eval()来支持.这里分享一个调用函数并传入需要参数的一个方法demo //动态调用自定义js方 ...
随机推荐
- Android DEX 基础
转载请标明出处:http://www.cnblogs.com/zhaoyanjun/p/5736305.html本文出自[赵彦军的博客] 1.什么是dex? 简单说就是优化后的android版.exe ...
- android universal-image-loader的使用
全局配置 android-image-loader的使用 public class Application extends Application { @Override public void on ...
- ASP.NET Button、ImageButton、LinkButton、HyperLink区别
这4个控件都属于WEB服务器控件,有很多相同的属性和事件.其区别如下所示. 在*.aspx页面中插入Button控件如以下代码所示.<asp:Button runat="server& ...
- Atitti.dw cc 2015 绿色版本安装总结
Atitti.dw cc 2015 绿色版本安装总结 1.1. 安装程序无法初始化.请下载adobe Support Advisor检测该问题.1 1.1.1. Adobe Application M ...
- MongoDB中的数据类型
mongoDB中存储的数据单元被称作文档.文档的格式与JSON很类似,只不过由于JSON表达的数据类型范围太小(null,boolean,numeric,string和object),mongoDB对 ...
- hadoop程序问题:java.lang.IllegalArgumentException: Wrong FS: hdfs:/ expected file:///
Java代码如下: FileSystem fs = FileSystem.get(conf); in = fs.open(new Path("hdfs://192.168.130.54:19 ...
- Keepalived+LVS+nginx双机热备
Keepalived简介 什么是Keepalived呢,keepalived观其名可知,保持存活,在网络里面就是保持在线了, 也就是所谓的高可用或热备,用来防止单点故障的发生. Keepalived采 ...
- 解决IE浏览器文字上面放无内容的元素选不中的方法
<div class="md1"> <p><i>sdgsgereryeryery</i></p> <label c ...
- NHibernate常见问题及解决方法
NHibernate常见问题及解决方法 曾经学过NHibernate的,但是自从工作到现在快一年了却从未用到过,近来要巩固一下却发现忘记了许多,一个"in expected: <end ...
- rxjs5.X系列 —— filter系列 api 笔记
欢迎指导与讨论 :) 前言 本文是笔者翻译 RxJS 5.X 官网各类operation操作系列的的第二篇 -- filter转换.如有错漏,希望大家指出提醒O(∩_∩)O.更详细的资料尽在rxjs官 ...