当前位置: 首页 > news >正文

WCF binding webHttpBinding is used to web browser in json format both in request and response

//D:\C\WcfService4\WcfService4\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" maxRequestLength="2147483647"/></system.web><system.serviceModel><services><service name="WcfService4.BookService"><endpoint address=""binding="webHttpBinding"bindingConfiguration="WebHttpBinding_IBookSerive"behaviorConfiguration="webBehavior_test"contract="WcfService4.IBookService"/><host><baseAddresses><add baseAddress="http://localhost:8080"/></baseAddresses></host></service></services><bindings><webHttpBinding><binding name="WebHttpBinding_IBookSerive"maxBufferPoolSize="2147483647"maxReceivedMessageSize="2147483647"><readerQuotasmaxDepth="2147483647"maxStringContentLength="2147483647"maxArrayLength="2147483647"maxBytesPerRead="2147483647"maxNameTableCharCount="2147483647"/></binding></webHttpBinding></bindings><behaviors><endpointBehaviors><behavior name="webBehavior_test"><webHttp/></behavior></endpointBehaviors><serviceBehaviors><behavior><!-- 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><serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /></system.serviceModel>
</configuration>//D:\C\WcfService4\WcfService4\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 WcfService4
{// 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(IsRequired = true,Order =1)]public long Id { get; set; }[DataMember(IsRequired = true, Order = 2)]public string Author { get; set; }[DataMember(IsRequired = true, Order = 3)]public string Abstract { get; set; }[DataMember(IsRequired = true, Order = 4)]public string Name { get; set; }[DataMember(IsRequired = true, Order = 5)]public string ISBN {  get; set; }[DataMember(IsRequired = true, Order = 6)]public string Title {  get; set; }[DataMember(IsRequired = true, Order = 7)]public string Topic {  get; set; }[DataMember(IsRequired =true, Order = 8)]public string Comment { get; set;  }[DataMember(IsRequired =true,Order = 9)]public string Content { get; set; }[DataMember(IsRequired =true,Order =10)]public string Summary {  get; set; }}
}//D:\C\WcfService4\WcfService4\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 WcfService4
{// 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 idx = 0;private long GetIncrementIdx(){return Interlocked.Increment(ref idx);}public List<Book> GetBooksList(int cnt){List<Book> bksList = new List<Book>();for (int i = 0; i < cnt; i++){long a = GetIncrementIdx();bksList.Add(new Book(){Id = a,Name = $"Name_{a}",ISBN = $"ISBN_{a}",Comment = $"Comment_{a}",Content = $"Content_{a}",Summary = $"Summary_{a}",Author = $"Author_{a}",Abstract = $"Abstract_{a}",Title = $"Title_{a}",Topic = $"Topic_{a}"});}return bksList;}}
}

 

 

http://localhost:55548/BookService.svc/GetBooksList?cnt=100

 

 

image

 

 

 

image

 

 

 

 

The follow will omit BookService.svc in url

//D:\C\WcfService4\WcfService4\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" maxRequestLength="2147483647"/></system.web><system.serviceModel><services><service name="WcfService4.BookService"><endpoint address=""binding="webHttpBinding"bindingConfiguration="WebHttpBinding_IBookSerive"behaviorConfiguration="webBehavior_test"contract="WcfService4.IBookService"/><host><baseAddresses><add baseAddress="http://localhost:8080"/></baseAddresses></host></service></services><bindings><webHttpBinding><binding name="WebHttpBinding_IBookSerive"maxBufferPoolSize="2147483647"maxReceivedMessageSize="2147483647"><readerQuotasmaxDepth="2147483647"maxStringContentLength="2147483647"maxArrayLength="2147483647"maxBytesPerRead="2147483647"maxNameTableCharCount="2147483647"/></binding></webHttpBinding></bindings><behaviors><endpointBehaviors><behavior name="webBehavior_test"><webHttp/></behavior></endpointBehaviors><serviceBehaviors><behavior><!-- 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><serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /></system.serviceModel><system.webServer><modules runAllManagedModulesForAllRequests="true"/><rewrite><rules><rule name="WCF Without SVC" stopProcessing="true"><match url="^(.*)$"/><conditions logicalGrouping="MatchAll"><add input="{REQUEST_FILENAME}" matchType="IsFile"negate="true"/><add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/></conditions><action type="Rewrite" url="BookService.svc/{R:1}"/></rule></rules></rewrite><directoryBrowse enabled="true"/></system.webServer>
</configuration>//D:\C\WcfService4\WcfService4\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 WcfService4
{// 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(IsRequired = true,Order =1)]public long Id { get; set; }[DataMember(IsRequired = true, Order = 2)]public string Author { get; set; }[DataMember(IsRequired = true, Order = 3)]public string Abstract { get; set; }[DataMember(IsRequired = true, Order = 4)]public string Name { get; set; }[DataMember(IsRequired = true, Order = 5)]public string ISBN {  get; set; }[DataMember(IsRequired = true, Order = 6)]public string Title {  get; set; }[DataMember(IsRequired = true, Order = 7)]public string Topic {  get; set; }[DataMember(IsRequired =true, Order = 8)]public string Comment { get; set;  }[DataMember(IsRequired =true,Order = 9)]public string Content { get; set; }[DataMember(IsRequired =true,Order =10)]public string Summary {  get; set; }}
}//D:\C\WcfService4\WcfService4\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 WcfService4
{// 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 idx = 0;private long GetIncrementIdx(){return Interlocked.Increment(ref idx);}public List<Book> GetBooksList(int cnt){List<Book> bksList = new List<Book>();for (int i = 0; i < cnt; i++){long a = GetIncrementIdx();bksList.Add(new Book(){Id = a,Name = $"Name_{a}",ISBN = $"ISBN_{a}",Comment = $"Comment_{a}",Content = $"Content_{a}",Summary = $"Summary_{a}",Author = $"Author_{a}",Abstract = $"Abstract_{a}",Title = $"Title_{a}",Topic = $"Topic_{a}"});}return bksList;}}
}

 

 

http://localhost:55548/getbookslist?cnt=300000

 

 

image

 

 

image

 

http://www.jsqmd.com/news/753327/

相关文章:

  • 2026届必备的降重复率网站横评
  • A08.使用WAF对金戈企业网站进行安全防护
  • 罗技PUBG鼠标宏压枪脚本:快速提升射击精准度的终极指南
  • 别再傻傻print了!用tqdm给你的Python脚本加个进度条(附Jupyter Notebook实战)
  • LangChain RAG开发套件:集成多模型与高级检索的快速构建指南
  • 新手工程师必看:手把手教你搞定TMS320F280049最小系统电源与晶振设计(附原理图)
  • 创业团队如何利用 Taotoken 多模型能力优化产品 AI 功能
  • GD32F103 SysTick定时器实战:从轮询到中断,两种延时方案怎么选?
  • GAC-KAN:边缘AI时代的轻量级GNSS干扰分类方案
  • 保姆级教程:用STM32F103和CubeMX实现汽车电池监控CAN通讯(附完整工程下载)
  • 2026最权威的降AI率平台实际效果
  • 物理农业撬动乡村振兴示范县申报与认定
  • AI推理动态调度系统RelayGen:智能匹配模型提升效率
  • AI 未来趋势:产业应用范式之变
  • 深圳GEO优化服务商推荐指南(2026版):如何选择靠谱的GEO营销推广优化合作伙伴 - 深圳昊客网络
  • 别再花钱买摄像头了!手把手教你用旧手机+OBS打造高清网课录制系统
  • AI语音驱动虚拟形象自然反应技术解析
  • 在 Node.js 后端服务中接入 Taotoken 实现智能客服回复
  • ODB++ 及Gerber 数据格式解析
  • Android 13+ 适配指南:Compose Scaffold侧滑菜单没了drawerContent?别慌,ModalNavigationDrawer救场
  • 1931年的大模型能写代码?GPT之父的穿越实验,撕开了AI界最大的谎言
  • RK3588安卓12平台Camera对焦调试实战:手把手搞定DW9763 VCM马达驱动移植
  • Arm C1-Nano核心缓存架构与性能优化指南
  • 大语言模型应用开发实战:从评估到部署的工程化指南
  • 别再为CAD和GIS数据对不上而头疼了!一份完整的ArcGIS for AutoCAD坐标系定义与数据套合指南
  • Kubernetes 1.29 + Calico 3.27 踩坑实录:内核版本不兼容导致网络插件启动失败的完整修复指南
  • 5分钟搞定PS4/PS5手柄Windows连接:DS4Windows终极配置指南
  • 告别内存泄漏:用TscanCode V2.14.24给你的C/C++代码做个深度体检(附规则配置避坑指南)
  • 基于CLIP与SAM的AI绘画自动抠图工具:原理、部署与优化
  • 从一次线上故障复盘说起:PostgreSQL主从切换的流复制配置与深度监控