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();
  • 相关阅读:
    【Office】Word排版
    小猪的压力
    SQL SERVER 自定义函数参数数量对调用时参数数量的影响
    工作效率
    C#使用SharpZipLib编辑zip包中内容
    SQL SERVER——自定义函数
    C#字符串编码
    在ASP.NET中启动SQL SERVER缓存
    C#延迟加载
    C#格式化DateTime时间
  • 原文地址:https://www.cnblogs.com/Winston/p/1155730.html
Copyright © 2011-2022 走看看