WCF 跨域TCP绑定
来源:互联网 发布:网络舆情日报 编辑:程序博客网 时间:2024/05/30 04:35
Silverlight4在跨域访问TCP时会读取Http 80端口的跨域策略文件,可以放IIS上,也可以在服务控制台托管Http服务
例子是控制台托管TCP服务和Http跨域策略文件服务
配置文件:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="ConsoleApplication1.DuxpexService">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="netTcpBindConfig"
contract="ConsoleApplication1.IDuxpexService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/DuxpexService/" />
<add baseAddress="net.tcp://localhost:4505/DuxpexService/" />
</baseAddresses>
</host>
</service>
<service name="ConsoleApplication1.DomainService">
<endpoint address="" behaviorConfiguration="DomainServiceBehavior"
binding="webHttpBinding" bindingConfiguration="" contract="ConsoleApplication1.IDomainService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="netTcpBindConfig">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="DomainServiceBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
</configuration>
TCP跨域策略文件ClientAccessPolicy.xml
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*" />
</allow-from>
<grant-to>
<socket-resource port="4502-4534" protocol="tcp"/>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
跨域服务:
[ServiceContract]
public interface IDomainService
{
[OperationContract]
[WebGet(UriTemplate = "ClientAccessPolicy.xml")]
Message ProvidePolicyFile();
}
public class DomainService : IDomainService
{
public System.ServiceModel.Channels.Message ProvidePolicyFile()
{
XmlReader reader = XmlReader.Create(@"ClientAccessPolicy.xml");
System.ServiceModel.Channels.Message result = Message.CreateMessage(MessageVersion.None, "", reader);
return result;
}
}
普通双向服务:
[ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Reentrant)]
public class DuxpexService : IDuxpexService
{
public int GetData()
{
IserviceCallBack client = OperationContext.Current.GetCallbackChannel<IserviceCallBack>();
client.ClientMethod();
return 10;
}
}
[ServiceContract(CallbackContract = typeof(IserviceCallBack))]
public interface IDuxpexService
{
[OperationContract]
int GetData();
}
public interface IserviceCallBack
{
[OperationContract(IsOneWay = true)]
void ClientMethod();
}
启动方法:
class Program
{
static void Main(string[] args)
{
ServiceHost host = new ServiceHost(typeof(DuxpexService));
ServiceHost domainhost = new ServiceHost(typeof(DomainService));
domainhost.Open();
host.Open();
Console.WriteLine("Service Start...");
Console.ReadLine();
domainhost.Close();
host.Close();
}
}
ClientAccessPolicy.xml
- WCF 跨域TCP绑定
- WCF 跨域 Http绑定
- WCF TCP协议绑定方式及错误问题整理
- WCF绑定
- tcp wcf
- WCF编程]WCF使用Net.tcp绑定时候出现错误:元数据包含无法解析的引用
- WCF绑定(Binding)
- WCF服务-绑定
- WCF绑定方式选择
- (三)、WCF绑定
- wcf 绑定(Bindings)
- WCF绑定类型选择
- wcf 绑定类型
- WCF源码(绑定)
- 深入学习WCF-绑定
- WCF常用绑定选择
- WCF绑定的选择
- WCF常用绑定 选择
- 无法取消隐藏受保护的操作系统文件的勾的方法
- IOS开发教程-01-IOS程序框架认识、XCode基础了解、MVC面向对象设计
- 思科路由器各种show命令的输出详解
- 每日一练
- PHP调用谷歌翻译实现翻译功能
- WCF 跨域TCP绑定
- Java写的为图片添加水印的软件(含源代码)
- 三年前自己的面试提纲
- 2.6.22.6最小内核构建
- jar打包命令-指定主类一次搞定!
- 大一下学期的总结
- 2012四月总结
- ASP.NET MVC 4 BundleTable的捆绑技术
- 马克·安德森:创造互联网未来的人