接口調用

svc中寫好接口方法

[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
       public 返回類型  方法名 (參數)
        {

        }

契約接口裏面要註冊這個方法

[ServiceContract]
   public interface 接口名
   {

    [OperationContract, WfJsonFormatter]

    public 返回類型  方法名 (參數)

   }

頁面調用的時候需要先配置服務

<add key="Service" value="

接口的地址.svc"/>

頁面後臺調用接口

 EndpointAddress endpoint = new EndpointAddress(System.Configuration.ConfigurationManager.AppSettings["Service"]);
       
           using (var factory = new WfClientChannelFactory<契約接口>(endpoint))
           {
               service.要調用的接口方法
           }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章