


















system.serviceModel ├─ bindings Channel/Route: Define protocol & maximum data capacity ├─ behaviors Operational rules, two separate types, no cross usage │ ├─ endpointBehaviors Gateway rules: REST enabling switch <webHttp/> │ └─ serviceBehaviors Global service rules: Metadata access & exception details ├─ services Core service entity │ └─ service Specific service instance │ └─ endpoint Access gateway ABC: Address + Binding + Contract └─ serviceHostingEnvironment IIS hosting configuration
//D:\C\WcfService8\WcfService8\Web.config <?xml version="1.0"?> <configuration> <appSettings> <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> </appSettings> <system.web> <compilation debug="true" targetFramework="4.8" /> <httpRuntime targetFramework="4.8"/> </system.web> <system.serviceModel> <bindings> <webHttpBinding> <binding name="WcfService8WebHttpBinding" transferMode="Buffered" receiveTimeout="00:10:00" sendTimeout="00:10:00" closeTimeout="00:10:00" openTimeout="00:10:00" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"> <readerQuotas maxStringContentLength="2147483647" maxNameTableCharCount="2147483647" maxDepth="2147483647" maxBytesPerRead="2147483647" maxArrayLength="2147483647"/> <security mode="None"/> </binding> </webHttpBinding> </bindings> <behaviors> <endpointBehaviors> <behavior name="Wcf8ServiceEndpointBehavior"> <webHttp/> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="WcfService8Behavior"> <!-- To avoid disclosing metadata information, set the values below to false before deployment --> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors> <services> <service name="WcfService8.BookService" behaviorConfiguration="WcfService8Behavior"> <endpoint address="" binding="webHttpBinding" bindingConfiguration="WcfService8WebHttpBinding" behaviorConfiguration="Wcf8ServiceEndpointBehavior" contract="WcfService8.IBookService"/> </service> </services> <protocolMapping> <add binding="basicHttpsBinding" scheme="https" /> </protocolMapping> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> <!-- To browse web app root directory during debugging, set the value below to true. Set to false before deployment to avoid disclosing web app folder information. --> <directoryBrowse enabled="true"/> </system.webServer> </configuration> //D:\C\WcfService8\WcfService8\IBookService.cs using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; namespace WcfService8 { // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IBookService" in both code and config file together. [ServiceContract] public interface IBookService { [OperationContract] [WebGet(UriTemplate = "GetBooksList?cnt={cnt}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] List<Book> GetBooksList(int cnt); } [DataContract] public class Book { [DataMember] public long Id { get; set; } [DataMember] public string Name { get; set; } [DataMember] public string ISBN { get; set; } [DataMember] public string Abstract { get; set; } [DataMember] public string Author { get; set; } [DataMember] public string Comment { get; set; } [DataMember] public string Content { get; set; } [DataMember] public string Summary { get; set; } [DataMember] public string Title { get; set; } [DataMember] public string Topic { get; set; } } } //D:\C\WcfService8\WcfService8\BookService.svc.cs using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; using System.Threading; namespace WcfService8 { // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "BookService" in code, svc and config file together. // NOTE: In order to launch WCF Test Client for testing this service, please select BookService.svc or BookService.svc.cs at the Solution Explorer and start debugging. public class BookService : IBookService { private static long id = 0; private static long GetIncrementId() { return Interlocked.Increment(ref id); } public List<Book> GetBooksList(int cnt) { List<Book> booksList = new List<Book>(); for(int i=0;i<cnt;i++) { var a=GetIncrementId(); booksList.Add(new Book() { Id=a, Name=$"Name_{a}", ISBN=$"ISBN_{a}_{Guid.NewGuid():N}", Abstract=$"Abstract_{a}", Author=$"Author_{a}", Comment=$"Comment_{a}", Content=$"Content_{a}", Summary=$"Summary_{a}", Title=$"Title_{a}", Topic=$"Topic_{a}" }); } return booksList; } } }
http://localhost:51374/BookService.svc/getbookslist?cnt=100000



此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。