zoukankan      html  css  js  c++  java
  • EndpointContracts

    In WCF, all services expose constracts. The contract is a platform-neutral(平台无关的) and standard way of describing what the service does. WCF defines four types of contracts.

    Service contracts
        Describe which operations the client can perform on the service.
    Data contracts   
        Define which data types are passed to and from the service. WCF defines implicit (隐式的)contracnts for built-in types such as int and stirng,  but we can define explicit data contracts.
    Fault contracts
        define which errors are raised by the service, and how the service handles and propagates (繁殖,传送)errors to its clients.
    Message contracts
        Allow the service to interact directly with messages. Message contracts can be typed or untyped, and are useful in interoperability cases and when there is an existing message format you have to comply with. as a WCF developer, we should use message contracts only rarely. :)

    Example: defining and implementing a service contract

    [ServiceContract]
    interface IMyContract
    {
        [OperationContract]
        string Hello();

        //will not be part of the contract
        string otherHello();
    }

    public class MyService:IMyContract
    {
        public string Hello()
        {
            return "this is a WCF Service";
        }

        //this method is not exposed as a service.
        public string otherHello()
        {
            return "can not call this method over WCF";
        }
    }


    Names and namespaces
        we can and should define a namespace for our contract. if it 's unspecified, the contract namespace defaults to http://tempuri.org. we can use Namespace property of the ServiceContract to provide a namespace.
    [ServiceContract(Namespace="myspace")]
        By default, the exposed name of the contract will be the name of the interface used. However, you could use an alias for a contract to expose a different name to the clients using the name property of the servicecontract
    [servicecontract(Name="IMyContract")]
    interface IMyOtherContract
    {...}
        In similar manner, the name the publicly exposed operation defaults to the method name, but u can use the Name property ot the operationContract to alias it to a different publicly exposed name:
    [OperationContract(Name="SomeOperatin")]
        string Hello();
  • 相关阅读:
    SpriteKit改变Node锚点其物理对象位置不对的解决
    亲热接触Redis-第二天(Redis Sentinel)
    Java设计模式(二)-单例模式
    Android—构建安全的Androidclient请求,避免非法请求
    自己主动化測试使用mybatis更新数据库信息实例
    UML回想-通信图
    第十六课 数组的引入 【项目1-5】
    被这个样式惊醒
    netty自定义解码器
    解决netty客户端接收报文不完整的情况
  • 原文地址:https://www.cnblogs.com/Winston/p/1155730.html
Copyright © 2011-2022 走看看