使用WCF双工
来源:互联网 发布:华云数据服务有限公司 编辑:程序博客网 时间:2024/04/30 16:03
说明:在代码中调试运行没问题,但在IIS中没有部署成功
1.新建的是Silveright项目,承载了WEB项目,使用的是Silverlight4.0
2.在web项目中添加了一个WCF服务
IPATransServices.cs 主要代码
[ServiceContract(CallbackContract = typeof(IPATransServicesCallBack))]
public interface IPATransServices
{
[OperationContract]
Dictionary<string, string> TransTable(string sTableName,
string sSourceServer, string sDesServer, string sUserID, string sPass);
}
[ServiceContract]
public interface IPATransServicesCallBack
{
[OperationContract(IsOneWay = true)]
void RecMsg(int intMax, int intValue, string strDesc);
}
PATransServices.svc.cs 主要代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Threading;
namespace PADataTrans.Web
{
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“PATransServices”。
public class PATransServices : IPATransServices
{
public Dictionary<string, string> TransTable(string sTableName,
string sSourceServer, string sDesServer, string sUserID, string sPass)
{
Dictionary<string, string> dicReturn = new Dictionary<string, string>();
dicReturn["Result"] = "False";
IPATransServicesCallBack client;
client = OperationContext.Current.GetCallbackChannel<IPATransServicesCallBack>();
for (int i = 1; i <= 1000; i++)
{
Thread.Sleep(100);
client.RecMsg(1000, i, "我在回调");
}
dicReturn["Result"] = "True";
return dicReturn;
}
}
}
由于要使用PollingDuplexHttpBinding来作为Service的endpoint的binding,所以需要对项目添加引用。右键项目,添加引用,选择浏览,然后关键的部分
Silverlight 版本 4 SDK 附带两个名为 System.ServiceModel.PollingDuplex.dll 的程序集。
WCF 双工服务使用其中一个程序集(位于 %ProgramFiles%\Microsoft SDKs\Silverlight\v4.0\Libraries\Server\ 目录下),
也就是我们要添加引用的程序集。另一个程序集(位于 %ProgramFiles%\Microsoft SDKs\Silverlight\v4.0\Libraries\Client\ 目录下)
在 Silverlight 双工客户端中使用。
楼主的路径是C:\Program Files\Microsoft SDKs\Silverlight\v4.0\Libraries\Server
说明:因为是在web项目中添加的WCF服务,所以在WEB项目中添加Server目录下的System.ServiceModel.PollingDuplex.dll
在Silverlight客户端项目中添加Client目录下的System.ServiceModel.PollingDuplex.dll
web.config文件配置很重要,也容易出错
<?xml version="1.0" encoding="utf-8"?>
<!--
有关如何配置 ASP.NET 应用程序的详细消息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<extensions>
<bindingExtensions>
<add name="pollingDuplexHttpBinding"
type="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement,
System.ServiceModel.PollingDuplex,Version=4.0.0.0,Culture=neutral"/>
</bindingExtensions>
</extensions>
<bindings>
<pollingDuplexHttpBinding>
<binding name="multipleMessagesPerPollPollingDuplexHttpBinding" duplexMode="MultipleMessagesPerPoll" maxOutputDelay="00:00:07">
</binding>
</pollingDuplexHttpBinding>
</bindings>
<services>
<service name="PADataTrans.Web.PATransServices">
<endpoint address="" binding="pollingDuplexHttpBinding"
bindingConfiguration="multipleMessagesPerPollPollingDuplexHttpBinding"
contract="PADataTrans.Web.IPATransServices">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
1.新建的是Silveright项目,承载了WEB项目,使用的是Silverlight4.0
2.在web项目中添加了一个WCF服务
IPATransServices.cs 主要代码
[ServiceContract(CallbackContract = typeof(IPATransServicesCallBack))]
public interface IPATransServices
{
[OperationContract]
Dictionary<string, string> TransTable(string sTableName,
string sSourceServer, string sDesServer, string sUserID, string sPass);
}
[ServiceContract]
public interface IPATransServicesCallBack
{
[OperationContract(IsOneWay = true)]
void RecMsg(int intMax, int intValue, string strDesc);
}
PATransServices.svc.cs 主要代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Threading;
namespace PADataTrans.Web
{
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“PATransServices”。
public class PATransServices : IPATransServices
{
public Dictionary<string, string> TransTable(string sTableName,
string sSourceServer, string sDesServer, string sUserID, string sPass)
{
Dictionary<string, string> dicReturn = new Dictionary<string, string>();
dicReturn["Result"] = "False";
IPATransServicesCallBack client;
client = OperationContext.Current.GetCallbackChannel<IPATransServicesCallBack>();
for (int i = 1; i <= 1000; i++)
{
Thread.Sleep(100);
client.RecMsg(1000, i, "我在回调");
}
dicReturn["Result"] = "True";
return dicReturn;
}
}
}
由于要使用PollingDuplexHttpBinding来作为Service的endpoint的binding,所以需要对项目添加引用。右键项目,添加引用,选择浏览,然后关键的部分
Silverlight 版本 4 SDK 附带两个名为 System.ServiceModel.PollingDuplex.dll 的程序集。
WCF 双工服务使用其中一个程序集(位于 %ProgramFiles%\Microsoft SDKs\Silverlight\v4.0\Libraries\Server\ 目录下),
也就是我们要添加引用的程序集。另一个程序集(位于 %ProgramFiles%\Microsoft SDKs\Silverlight\v4.0\Libraries\Client\ 目录下)
在 Silverlight 双工客户端中使用。
楼主的路径是C:\Program Files\Microsoft SDKs\Silverlight\v4.0\Libraries\Server
说明:因为是在web项目中添加的WCF服务,所以在WEB项目中添加Server目录下的System.ServiceModel.PollingDuplex.dll
在Silverlight客户端项目中添加Client目录下的System.ServiceModel.PollingDuplex.dll
web.config文件配置很重要,也容易出错
<?xml version="1.0" encoding="utf-8"?>
<!--
有关如何配置 ASP.NET 应用程序的详细消息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<extensions>
<bindingExtensions>
<add name="pollingDuplexHttpBinding"
type="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement,
System.ServiceModel.PollingDuplex,Version=4.0.0.0,Culture=neutral"/>
</bindingExtensions>
</extensions>
<bindings>
<pollingDuplexHttpBinding>
<binding name="multipleMessagesPerPollPollingDuplexHttpBinding" duplexMode="MultipleMessagesPerPoll" maxOutputDelay="00:00:07">
</binding>
</pollingDuplexHttpBinding>
</bindings>
<services>
<service name="PADataTrans.Web.PATransServices">
<endpoint address="" binding="pollingDuplexHttpBinding"
bindingConfiguration="multipleMessagesPerPollPollingDuplexHttpBinding"
contract="PADataTrans.Web.IPATransServices">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
- 使用WCF双工
- wcf双工
- wcf使用netTcpBinding实现双工通信
- Winfrom 使用WCF 实现双工通讯
- WCF使用入门(一)【基于双工通信的WCF应用】
- WCF之双工服务
- WCF 双工开发笔记
- WCF双工通信
- WCF双工代码
- WCF全双工数据传输
- WCF双工通道
- WCF实现双工通信
- WCF 双工模式
- WCF学习之“双工服务”
- silverlight中Wcf双工通信
- WCF中实现双工通信
- Silverlight与WCF的双工通信
- silverlight之wcf双工通讯学习笔记
- spring事务管理使用心得
- android view background 问题
- 内核漏洞分析blog
- Eclipse 最牛的几款插件
- 内核漏洞分析blog
- 使用WCF双工
- hql语句用distinct问题
- mac 启动ftp服务,关闭FTP服务
- org.springframework.web.filter.CharacterEncodingFilter的解决方法
- Silverlight网站IIS部署问题
- PHP中获取当前页面的完整URL
- 算法导论笔记第二章——算法入门
- 远程查询,报这个错,你见过吗?
- 听”地铁上的英语“,你怎么看?