[ ServiceContract ] public interface IService1 { [ OperationContract ] IEnumerable < tempCalendar > readGoogleData( int intStartIkey, int intEndIkey); [ OperationContract ] bool writeGoogleData( tempCalendar updateData); } [ DataContract ] public class tempCalendar { [ DataMember ] public int ikey { get ; set ; } [ DataMember ] public string sendParameter { get ; set ; } } |
實作介面的類別
public class Service1 : IService1 { GoogleEntities googleEntityObj = new GoogleEntities (); public IEnumerable < tempCalendar > readGoogleData( int intStartIkey, int intEndIkey) { IEnumerable < tempCalendar > tempCalendarList = from c in googleEntityObj.Calendar Where c.ikey >= intStartIkey && c.ikey <= intEndIkey select new tempCalendar { ikey=c.ikey, sendParameter=c. 上傳參數 }; return tempCalendarList; } public bool writeGoogleData( tempCalendar updateData) { var original = googleEntityObj.Calendar.Find(updateData.ikey); original. 上傳完成 = updateData.isSendGoogleOK; original. 結果訊息 = updateData.sendMessage;; googleEntityObj.SaveChanges(); return true ; } } |
< system.serviceModel > < bindings > < basicHttpBinding > <!-- 預設允許大量傳輸 --> < binding name = cusBinding maxBufferSize = 64000000 maxReceivedMessageSize = 64000000 /> </ basicHttpBinding > </ bindings > < client > <!-- 連線端口設為 basicHttpBinding 具名管線, --> < endpoint binding = basicHttpBinding bindingConfiguration = cusBinding contract = WcfService1.IService1 /> </ client > < services > < service name = WcfService1.Service1 > < endpoint address = binding = basicHttpBinding bindingConfiguration = cusBinding contract = WcfService1.IService1 /> </ service > </ services > < behaviors > < serviceBehaviors > < behavior name = > < serviceMetadata httpGetEnabled = true httpsGetEnabled = true /> < serviceDebug includeExceptionDetailInFaults = false /> <!-- 預設連線數允許到 100 --> < serviceThrottling maxConcurrentCalls = 100 maxConcurrentSessions = 50 maxConcurrentInstances = 50 /> </ behavior > </ serviceBehaviors > </ behaviors > < protocolMapping > < add binding = basicHttpsBinding scheme = https /> </ protocolMapping > < serviceHostingEnvironment aspNetCompatibilityEnabled = true multipleSiteBindingsEnabled = true /> </ system.serviceModel > |
public IEnumerable < tempCalendar > serviceReadGoogleData( int intStartIkey, int intEndIkey) { try { BasicHttpBinding myBinding = new BasicHttpBinding (); EndpointAddress myEndpoint = new EndpointAddress ( ); ChannelFactory < IService1 > myChannelFactory = new ChannelFactory < IService1 >(myBinding, myEndpoint); IService1 wcfClient1 = myChannelFactory.CreateChannel(); return wcfClient1.readGoogleData(intStartIkey, intEndIkey); } catch ( Exception ex) { throw new Exception (ex.Message); } } |
設定 web協定
[ OperationContract ] [ WebInvoke (Method = , UriTemplate = , RequestFormat = WebMessageFormat .Json, ResponseFormat = WebMessageFormat .Json, BodyStyle = WebMessageBodyStyle .WrappedRequest)] bool writeToGoogleCalendar( string orgIkey); |
public bool writeToGoogleCalendar( string orgIkey) { return true ; } |
< system.serviceModel > < bindings > </ bindings > < client > < endpoint binding = webHttpBinding bindingConfiguration = contract = WcfService1.IService1 /> </ client > < services > < service name = WcfService1.Service1 > < endpoint address = behaviorConfiguration = webBehavior binding = webHttpBinding bindingConfiguration = contract = WcfService1.IService1 /> </ service > </ services > < behaviors > < endpointBehaviors > < behavior name = webBehavior > < webHttp /> </ behavior > </ endpointBehaviors > < serviceBehaviors > < behavior name = > < serviceMetadata httpGetEnabled = true httpsGetEnabled = true /> < serviceDebug includeExceptionDetailInFaults = false /> < serviceThrottling maxConcurrentCalls = 100 maxConcurrentSessions = 50 maxConcurrentInstances = 50 /> </ behavior > </ serviceBehaviors > </ behaviors > |