Siverlight与WCF之间的通信按照理论有以下几种方式
协议 宿主
http console
http IIS
tcp console
tcp IIS
当然还有windows服务,winform等等,这里仅举出了常见的两种。
这次测试的是silverlight使用TCP访问寄宿在控制台上的wcf服务
代码结构:
双工访问的关键点在于
1,比普通的WCF服务多了一个回调契约
namespace WCFlibrary
{
[ServiceContract(CallbackContract = typeof(IUpdateClIEnt))]
public interface IUpdateUser
{
[OperationContract]
WCFModel.User Update(WCFModel.User User);
}
[ServiceContract]
public interface IUpdateClIEnt
{
[OperationContract(IsOneWay = true)]
voID Say(string fromServerString);
}
}
2,app.config配置
<service behaviorConfiguration="WCFlibrary.UpdateUserBehavior" name="WCFlibrary.UpdateUser">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:4503/UpdateUser"/>
</baseAddresses>
</host>
<endpoint address="" binding="netTcpBinding" contract="WCFlibrary.IUpdateUser" bindingConfiguration="netTcpBindConfig"></endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" ></endpoint>
</service>
3,一定要在本机的IIS根目录放置一个策略文件
4,Host关键代码
class Program
{
static voID Main(string[] args)
{
MyHost.open();
System.Console.Writeline("服t务?已?经-启?动ˉ... 敲?任?意a键ü停£止1服t务?");
System.Console.Readline();
MyHost.Close();
}
}
public class MyHost
{
static ServiceHost host = null;
public static voID open()
{
host = new ServiceHost(typeof(WCFlibrary.UpdateUser));
host.open();
host = new ServiceHost(typeof(WCFlibrary.AddService));
host.open();
}
public static voID Close()
{
if (host != null && host.State == CommunicationState.Opened)
{
host.Close();
}
host = null; } }
以上是内存溢出为你收集整理的Silverlight通过TCP协议访问双工模式的WCF(Host在控制台)全部内容,希望文章能够帮你解决Silverlight通过TCP协议访问双工模式的WCF(Host在控制台)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)