WCF tips

配置文件方式设置EndPoint(ABC)

基本配置

<system.serviceModel>
    <services>
        <service name="MyNamespace.MyService">
            <endpoint address="http://localhost:8000/MyService" binding="wsHttpBinding" contract="MyNamespace.IMyContract"/>
        </service>
    </services>
</system.serviceModel>

为一个Service配置多个结点

<service name="MyService">
    <endpoint address="http://localhost:8000/MyService" binding="wsHttpBinding" contract="IMyContract"/>
    <endpoint address="net.tcp://localhost:8001/MyService" binding="netTcpBinding" contract="IMyContract"/>
    <endpoint address="net.tcp://localhost:8002/MyService" binding="netTcpBinding" contract="IMyOtherContract"/>
</service>

基地址

<system.serviceModel>
    <services>
        <service name="MyNamespace.MyService">
            <host>
                <baseAddresses>
                    <add baseAddress="net.tcp://localhost:8001/"/>
                    <add baseAddress="http://localhost:8002/"/>
                </baseAddresses>
            </host>
        </service>
    </services>
</system.serviceModel>

使用绑定

<system.serviceModel>
    <services>
        <service name="MyService">
            <endpoint address="net.tcp://localhost:8000/MyService" bindingConfiguration="TransactionalTCP" binding="netTcpBinding" contract="IMyContract"/>
            <endpoint address="net.tcp://localhost:8001/MyService" bindingConfiguration="TransactionalTCP" binding="netTcpBinding" contract="IMyOtherContract"/>
        </service>
    </services>
    <bindings>
        <netTcpBinding>
            <binding name="TransactionalTCP" transactionFlow="true"/>
        </netTcpBinding>
    </bindings>
</system.serviceModel>

默认绑定

应用到所有没有直接指定bindingConfiguration的EndPoint。一种绑定类型BasicHttpBinding/netTcpBinding/wsHttpBinding/...只能有一个默认配置

<netTcpBinding>
    <binding transactionFlow="true"/> <!--没有name属性-->
</netTcpBinding>

代码方式设置EndPoint

基本方式

ServiceHost host = new ServiceHost(typeof(MyService));
Binding wsBinding = new WSHttpBinding();
Binding tcpBinding = new NetTcpBinding();
host.AddServiceEndpoint(typeof(IMyContract),wsBinding,
"http://localhost:8000/MyService");
host.AddServiceEndpoint(typeof(IMyContract),tcpBinding,
"net.tcp://localhost:8001/MyService");
host.AddServiceEndpoint(typeof(IMyOtherContract),tcpBinding,
"net.tcp://localhost:8002/MyService");
host.Open();

使用基地址

Uri tcpBaseAddress = new Uri("net.tcp://localhost:8000/");
ServiceHost host = new ServiceHost(typeof(MyService),tcpBaseAddress);
Binding tcpBinding = new NetTcpBinding();
//Use base address as address
host.AddServiceEndpoint(typeof(IMyContract),tcpBinding,"");
//Add relative address
host.AddServiceEndpoint(typeof(IMyContract),tcpBinding,"MyService");
//Ignore base address
host.AddServiceEndpoint(typeof(IMyContract),tcpBinding,
"net.tcp://localhost:8001/MyService");
host.Open();

使用绑定

ServiceHost host = new ServiceHost(typeof(MyService)); //没有基地址
NetTcpBinding tcpBinding = new NetTcpBinding();
tcpBinding.TransactionFlow = true; //设置绑定属性
host.AddServiceEndpoint(typeof(IMyContract),tcpBinding,
"net.tcp://localhost:8000/MyService");
host.Open();

使用下列构造函数,可以使用配置文件中的指定绑定配置来初始化绑定,或是使用空串来使用默认的绑定配置

public class NetTcpBinding : Binding,...
{
public NetTcpBinding(string configurationName);
//More members
}
时间: 2024-11-05 18:46:09

WCF tips的相关文章

WCF学习资源收集汇总

1.WCF编程 http://www.cnblogs.com/wengyuli/category/217446.html 2.wcf热门问题编程示例 http://blog.csdn.net/book_frank_xl/article/category/610975/4 3.我的WCF之旅 http://www.cnblogs.com/artech/archive/2007/09/15/893838.html 4.WCF面向服务应用程序系列 http://www.cnblogs.com/xinh

调用WCF Data Service的几点Tips

使用Linq实现sql in statement的时候,用EF的时候可以通过Contains.Exists的方法实现.但是在使用WCF Data Service的context的时候,会报不支持该方法的错误.解决方案就是加上AsEnumerable(). var products = from p in ctx.V_Product.AsEnumerable() where catalogs.Exists(c => c.CatalogID == p.CatalogID) select p 主从表级

WCF Extensibility

Over the next months I intend on writing a series of posts about the (many) extensibility points from WCF (up to .NET Framework 4.0). The cadence should be around one new post every 1-2 weeks (depending on the workload I have at work). WCF is a very

Learning WCF Chapter2 WCF Contracts and Serialization

So far I’ve talked about the standards behind it all,but in fact WCF hides most of this from the developer by providing a programming interface for designing service contracts and controlling the message format. Application messaging requirementsare

Learning WCF Chapter1 Creating a New Service from Scratch

You’re about to be introduced to the WCF service. This lab isn’t your typical “Hello World”—it’s “Hello Indigo”! In this lab,you will learn how to build a new WCF service and in the process learn the minimum requirements of service development and co

Android应用程序性能优化Tips

主要介绍一些小细节的优化技巧,虽然这些小技巧不能较大幅度的提升应用性能,但是恰当的运用这些小技巧并发生累积效应的时候,对于整个App的性能提升还是有不小作用的.通常来说,选择合适的算法与数据结构会是你首要考虑的因素,在这篇文章中不会涉及这方面的知识点.你应该使用这篇文章中的小技巧作为平时写代码的习惯,这样能够提升代码的效率. 通常来说,高效的代码需要满足下面两个原则: 不要做冗余的工作 尽量避免执行过多的内存分配操作 To ensure your app performs well across

程序员取悦女朋友的正确姿势---Tips(iOS美容篇)

前言 女孩子都喜欢用美图工具进行图片美容,近来无事时,特意为某人写了个自定义图片滤镜生成器,安装到手机即可完成自定义滤镜渲染照片.app独一无二,虽简亦繁. JH定律:魔镜:最漂亮的女人是你老婆魔镜:程序员不是木头人 核心技术 图片滤镜核心技术的基本思路如下: 核心技术流程 具体流程 1.创建一个图像处理工具类 注:该类实例包括一个图像处理方法,该方法在传入原始图像和一个颜色矩阵后生成一个处理好的图像. @interface JHFeilterManager : NSObject @proper

.NET4.5中WCF中默认生成的basicHttpsBinding的研究

起因: 使用.net4.5建立了一个空白的WCF服务.默认使用的绑定配置是basicHttpsBinding. 问题发现: 1.用客户端进行服务引用,生成了默认的配置文件,其中绑定配置是basicHttpBinding. 2.因为需要单次传递大批量数据,所以修改绑定配置,如下: <basicHttpBinding> <binding name="BasicHttpBinding_IService" closeTimeout="00:10:00" r

PHP调用WCF提供的方法

一.准备工作 1.安装wampserver:过程略 2.配置wampserver: 2.1打开php.ini文件,去掉 ;extension=php_soap.dll 这里那个分号. 也有说把这个 ;extension=php_openssl.dll前面的分号也去掉的. 2.2 如上图,将php_soap打上√. 2.3 如上图,打开httpd.conf文件,找到Listen 80 ,将80端口改成一个较大的端口,如8000.因为80端口也能别的程序用着. 在这个directory里面有php页