惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
Vercel News
Vercel News
Last Week in AI
Last Week in AI
H
Help Net Security
The Cloudflare Blog
L
LangChain Blog
Microsoft Security Blog
Microsoft Security Blog
B
Blog RSS Feed
云风的 BLOG
云风的 BLOG
I
InfoQ
U
Unit 42
美团技术团队
人人都是产品经理
人人都是产品经理
雷峰网
雷峰网
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
Y
Y Combinator Blog
Hugging Face - Blog
Hugging Face - Blog
A
About on SuperTechFans
宝玉的分享
宝玉的分享
量子位
博客园_首页

博客园 - FredGrit

WPF customize via three combied custom controls WPF DataGrid DataGridTemplateColumn DataTemplate ContentPresenter ContentTemplate WPF Customcontrol NumUpDownScroller WPF CustomControl override Template in Generic.xaml and invoke different style WPF HierarchicalDataTemplate customize via ToggleButton WPF DataGrid DataGridTemplateColumn DataTemplate call predefined DataTemplate via ContentPresenter and ContentTemplate WPF ListBox load data via contentcontrol an ItemTemplate WPF DataGrid load data from Asp.Net Core WebAPI WPF TreeView HierarchicalDataTemplate with grouped Data WPF display grouped data with GroupBox and ItemsControl WPF two listbox scroll syncchronously via behavior WPF invoke data from WebAPI,DataGridTemplate call pre defined DataTemplate via ContentPresenter WPF ListBox load data from WCF WPF datagrid load data from WCF via json, export selected items to json file WPF ItemsControl load data from WCF,DataTemplate, ContentControl WPF customize rotated wheel relentlessly via custom control WPF embed DataTemplate in HierchicalDataTemplate of TreeView WPF ContentControl, ItemsControl, ItemsPanelTemplate,VirtualizingStackPanel,convert xml string to List<T> WPF parse web.config recursively, TreeView and HierarchicalDataTemplate WPF Custom control in cs and Generic.xaml WPF ContextMenu independent visual tree resolved via Freezable implemented class WPF custom control GetTemplateChild vs FindName,NameScope separation between Logical Tree and Visual Tree, WPF ListBox ListView Datatemplate, parse xml to List via XmlSerializer and StringReader WPF TreeView HierarchicalDataTemplate, parse xml via traverse in XmlElement WPF parse xml via [XmRoot] and [XmlElement] attributes together, contentcontrol's template is ControlTemplate from Resources WPF ContentControl invoke Template from resource, reuse datatemplate WPF deserialize xml string as List via [XmlRoot] and [XmlElement] attribute WPF ContentControl Template WPF DatagridTemplate Binding DataTemplate WPF TreeView explicitly given key name to HierarchicalDataTemplate
WCF binding webHttpBinding is used to web browser in json...
FredGrit · 2026-05-04 · via 博客园 - FredGrit
//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">
                  <readerQuotas
                      maxDepth="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">
                  <readerQuotas
                      maxDepth="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