WCF and Web Service

web service (.asmx)

方法描述加申明 [WebMethod]

服务端不需要什么配置,开发和普通方法一样

 

客户端需要配置,添加引用

 

WCF (.svc)

先定义一个接口契约,再实现方法

[ServiceContract]
    public interface IService1
    {

        [OperationContract]
        string GetData(int value);

    }  

服务端需要一些配置  <system.serviceModel>

客户端同样需要配置,添加引用,其它一样。

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService1" />
                <binding name="WebService1Soap" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:54361/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
                name="BasicHttpBinding_IService1" />
            <endpoint address="http://localhost:57712/WebService1.asmx" binding="basicHttpBinding"
                bindingConfiguration="WebService1Soap" contract="webref2.WebService1Soap"
                name="WebService1Soap" />
        </client>
    </system.serviceModel>

  

posted @ 2017-09-01 13:48  chy710  阅读(25)  评论(0)    收藏  举报