标签:style blog http color io os 使用 ar for
在控制台部署wcf双工 这个可以被silverlight 使用 <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <bindings> <netTcpBinding> <binding name="netTcpBindConfig"> <security mode="None"/> </binding> </netTcpBinding> </bindings> <services> <service behaviorConfiguration="WCFLibrary.UpdateUserBehavior" name="WcfService1.Service1"> <host> <baseAddresses> <add baseAddress="net.tcp://localhost:4503/Service1"/> </baseAddresses> </host> <endpoint address="" binding="netTcpBinding" contract="WcfService1.IService1" bindingConfiguration="netTcpBindConfig"></endpoint> <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" ></endpoint> </service> </services> <behaviors> <serviceBehaviors> <behavior name="WCFLibrary.UpdateUserBehavior"> <serviceMetadata/> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration>
这个貌似不能被silverlight使用 <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0"/> <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/> </system.web> <system.serviceModel> <bindings> <netTcpBinding> <binding name="tcpBindingConfig1"> <security mode="None"/> </binding> </netTcpBinding> </bindings> <services> <service name="WcfService1.Service1"> <endpoint address="" binding="netTcpBinding" bindingConfiguration="tcpBindingConfig1" contract="WcfService1.IService1"/> <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/> <host> <baseAddresses> <add baseAddress = "http://localhost:9999/WcfStudy3/Service1" /> <add baseAddress = "net.tcp://localhost:8888/WcfStudy3/Service1" /> </baseAddresses> </host> </service> </services> <behaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="False"/> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment aspNetCompatibilityEnabled="False" multipleSiteBindingsEnabled="true"/> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </configuration>
这个可以部署在IIS中 也是双工 这是wcf的配置文件 <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0"/> <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/> </system.web> <system.serviceModel> <bindings> <netTcpBinding> <binding name="tcpBindingConfig1"> <security mode="None"/> </binding> </netTcpBinding> </bindings> <services> <service name="WcfService1.Service1"> <endpoint address="" binding="netTcpBinding" bindingConfiguration="tcpBindingConfig1" contract="WcfService1.IService1"/> <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/> <host> <baseAddresses> <add baseAddress="net.tcp://localhost:4502/Service1.svc"/> </baseAddresses> </host> </service> </services> <behaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="False"/> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment aspNetCompatibilityEnabled="False" multipleSiteBindingsEnabled="true"/> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </configuration>
这是wcf程序 using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; namespace WcfService1 { // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IService1”。 [ServiceContract(CallbackContract = typeof(iMyclass))] public interface IService1 { [OperationContract] string Send(string id,string pid, string str); [OperationContract] string Register(string id); [OperationContract] List<string> ALLhost(); } [ServiceContract] public interface iMyclass { [OperationContract(IsOneWay = true)]//回调函数方法必须加IsOneWay=true void Reciver(string str); } } using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; namespace WcfService1 { // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“Service1”。 public class Service1 : IService1 { public static Dictionary<string, iMyclass> hostdic; public static List<string> allhost; /// <summary> /// /// </summary> /// <param name="id">发送人</param> /// <param name="pid">接受人</param> /// <param name="str">内容</param> /// <returns></returns> public string Send(string id,string pid, string str) { try { foreach (var d in hostdic) { if (d.Key == pid) { d.Value.Reciver(id+"发送:"+str); } } //iMyclass myclass= OperationContext.Current.GetCallbackChannel<iMyclass>(); //myclass.Reciver("你好"); return "1"; } catch (Exception ex) { return ex.Message; } } public List<string> ALLhost() { return allhost; } public string Register(string id) { if (hostdic == null) { hostdic = new Dictionary<string, iMyclass>(); } if (allhost == null) { allhost = new List<string>(); } iMyclass imyclass = OperationContext.Current.GetCallbackChannel<iMyclass>(); hostdic.Add(id, imyclass); allhost.Add(id); return id; } } }
标签:style blog http color io os 使用 ar for
原文地址:http://www.cnblogs.com/wlzhang/p/3969554.html