According to instructor Jiang Jinnan's blog, the ending point of WCF consists of three elements: Address, Binding, and Contract ), the description can be written as Endpoint = ABC.
Address: The address determines the service location and solves the service addressing problem.
Binding: Binding implements all the details of communication, including network transmission, message encoding, and other processes to implement certain functions. The binding types include BasicHttpBinding, WsHttpBinding, and NetTcpBinding.
Contract: A contract is an abstraction of service operations and a definition of the message exchange mode and message structure.
The above content is excerpted from instructor Jiang's blog. Understanding this is helpful for configuring WCF.
Then configure a WCF step by step.
The first is the server,
The core of a WCF is the endpoint. Write the endpoint first,
Copy codeThe Code is as follows: <services>
<Service name = "BLL. Logic" behaviorConfiguration = "te">
<Host>
<BaseAddresses>
<Add baseAddress = "http: // localhost: 9091/logicService"/>
</BaseAddresses>
</Host>
<Endpoint address = "" binding = "ws2007HttpBinding" contract = "BLL. ILogic" bindingConfiguration = "transportWS2007HttpBinding"/>
</Service>
</Services>
From the address (address) binding (binding), Contract (Contract) attributes of <endpoint> ), these attributes are exactly the "ABC" mentioned above. Note that the values BasicHttpBinding, WsHttpBinding, and NetTcpBinding are entered in binding. Which binding should be set in bindingConfiguration, the value is the name value of <binding>. The fully qualified name of the contract interface of contract in the contract Project. The binding configuration will be introduced later. Address is not set. Here, an address is specified in After the introduction of <endpoint>, let's look at the outside of <endpoint>. <Endpoint> included in <services> <service>. <serivces> here is a set that can contain multiple services, each Service has a specific name, and name is the fully qualified name of the Service class that implements the Contract in the project. Here, we have made some settings for servicebehavior. The specific content is in <servicebehavior> named te.
Since binding and behavior are involved in the above configuration, We will configure the two respectively.Copy codeThe Code is as follows: <bindings>
<Ws2007HttpBinding>
<Binding name = "transportWS2007HttpBinding" maxcompute edmessagesize = "2147483647" maxBufferPoolSize = "2147483647">
<ReaderQuotas maxArrayLength = "2147483647" maxBytesPerRead = "2147483647" maxDepth = "2147483647" maxNameTableCharCount = "2147483647" maxStringContentLength = "2147483647"/>
<Security mode = "Message">
<Transport clientCredentialType = "None"/>
</Security>
</Binding>
</Ws2007HttpBinding>
<BasicHttpBinding>
<Binding name = "newBinding" maxBufferPoolSize = "21474835647" maxcompute edmessagesize = "2147483647" messageEncoding = "Text">
<ReaderQuotas maxDepth = "2147483647" maxStringContentLength = "2147483647" maxArrayLength = "2147483647" maxBytesPerRead = "2147483647" maxNameTableCharCount = "2147483647"/>
</Binding>
</BasicHttpBinding>
</Bindings>
Like services, bindings is also a set that contains various types of binding. For example, <binding> in <ws2007HttpBinding> is the exact binding, <endpoint> in use, the bindingConfiguration name must be set to external, and the binding type cannot be incorrect. The sub-nodes and attributes in <binding> are not described in detail. If you want to transmit large data through WCF, set the binding attributes and <readerQuotas>.Copy codeThe Code is as follows: <behaviors>
<ServiceBehaviors>
<Behavior name = "te">
<ServiceMetadata httpGetEnabled = "true"/>
</Behavior>
</ServiceBehaviors>
</Behaviors>
Finally, it's behaviors. Likewise, behaviors is a set of two types: serviceBehaviors for service configuration and endpointBehaviors for endpoint configuration. The two types are both a set. The child node <behavior> is their subitem, And the name is used to distinguish the behavior. We will not talk about any attributes or subitem in it, fill in the name value of behavior in the behaviorConfiguration attribute of the corresponding service or endpoint.
The configuration of the server end is here, and then to the client.Copy codeThe Code is as follows: <client>
<Endpoint address = "http: // localhost: 9091/logicService" binding = "ws2007HttpBinding"
BindingConfiguration = "WS2007HttpBinding_ILogic" contract = "Proxy. ILogic"
Name = "WS2007HttpBinding_ILogic">
</Endpoint>
</Client>
The first is the endpoint. the endpoint of the client is placed in the client, which also contains "ABC". The address must be the same as that configured on the server. Otherwise, the corresponding service cannot be found. The type of binding must be the same as that of the server. contract is the fully qualified name of the class in the code generated by svcutil or other tools.Copy codeThe Code is as follows: <ws2007HttpBinding>
<Binding name = "WS2007HttpBinding_ILogic" closeTimeout = "00:01:00"
OpenTimeout = "00:01:00" receiveTimeout = "00:10:00" sendTimeout = "00:01:00"
BypassProxyOnLocal = "false" transactionFlow = "false" hostNameComparisonMode = "StrongWildcard"
MaxBufferPoolSize = "524288" maxcompute edmessagesize = "2147483647"
MessageEncoding = "Text" textEncoding = "UTF-8" useDefaultWebProxy = "true"
AllowCookies = "false">
<ReaderQuotas maxDepth = "32" maxStringContentLength = "1024" maxArrayLength = "2147483647"
MaxBytesPerRead = "4096" maxNameTableCharCount = "16384"/>
<ReliableSession ordered = "true" inactivityTimeout = "00:10:00"
Enabled = "false"/>
</Binding>
</Ws2007HttpBinding>
Another thing to mention is this binding. The client binding requires a little more configuration than the server-side closeTimeout, openTimeout, and receiveTimeout, which are roughly the same as the server-side binding.
In addition, if you want to transmit large data, you can configure it as per me. In fact, this configuration is applicable to the transmission of several MB of images. As a hacker, the understanding of many things is not thorough enough. Please criticize and point out the above. Thank you!