WCF knowledge point

Source: Internet
Author: User

The session is terminated, and the corresponding service instance is also identified as a recycle object,

When the agent of the client is disabled, the corresponding service instance will also disappear.

So we can say that the session displayed on the client is actually implemented by the corresponding instancing. Now we use the instance context mode of percall, and the proxy status cannot be retained. If we set the instance context mode to persession, the running result will be as expected.

 

2. The created channel has the session feature only when wshttpbinding is enabled for security or reliable session. Solution
<Servicebehaviors>
6: <behavior name = "highconcurrencybehavior">
7: <servicethrottling maxconcurrentsessions = "20"/>
8: </behavior>
9: </servicebehaviors>

 

3. WCF imposes a requirement on the WCF client to limit the concurrent sessions of the service, that is, it should be closed in time when the Service proxy is no longer used. Sessions based on the Service proxy object will be closed as the Service proxy is closed. When the server processes client requests, if the number of concurrent sessions exceeds the permitted range, subsequent requests will be placed in the waiting queue to wait for the end of the existing session. For the client, a timeoutexception exception is thrown if the service call does not receive a response within the allowed timeout period (1 minute by default ).

4. In fact, disabling the Service proxy is meaningless for the datagram channel.

5. Create an ordercollection object and add 10 order objects. If this object is serialized, what is the number of objects to be serialized? In this case, the ordercollection object is regarded as one, and each order object is regarded as one. The order object has four attributes and sets the serialization quantity,
<Behaviors>
<Servicebehaviors>
<Behavior name = "serializationlimitationbehavior">
<Datacontractserializer maxitemsinobjectgraph = "51"/>
</Behavior>
</Servicebehaviors>
</Behaviors>

6. Whether or not the Service proxy is disabled does not affect the datagram channel.

7 Throttling is defined by the servicethrottlingbehavior class and includes three important attributes: maxconcurrentcils, maxconcurrentsessions, and maxconcurrentinstances. Their default values are 16, 10, and 26, respectively.

8. The datagram channel "means that all messages in the channel are not associated with the channel. When using a datagram channel, if the input or output operation fails, the next operation is usually not affected and the same channel can be reused. Therefore, the datagram channel generally does not have errors.

In contrast, "session channel" is a channel connected to another endpoint. Messages in a session at one end are always associated with the same session at the other end. In addition, the two participants of a session must agree that the session is successful only when the requirements of the conversation are met. If they cannot agree, the session channel may fail.

 

9 public partial class cnblogswcfclient: idisposable

02 {

03 void idisposable. Dispose ()

04 {

05 try {This. Close ();}

06 catch (communicationexception E)

07 {

08 this. Abort ();

09}

10 catch (timeoutexception E)

11 {

12 This. Abort ();

13}

14 Catch (exception E)

15 {

16 this. Abort ();

17}

18}

19}

 

10 reference Configuration:
<Nettcpbinding>
<Binding name = "nettcpbindconfig" closetimeout = "00:30:00"
Opentimeout = "00:30:00" receivetimeout = "00:30:00" sendtimeout = "00:30:00"
Transactionflow = "false" transfermode = "buffered" transactionprotocol = "oletransactions"
Hostnamecomparisonmode = "strongwildcard" listenbacklog = "10"
Maxbufferpoolsize = "2147483647" maxbuffersize = "2147483647" maxconnections = "1000"
Maxcompute edmessagesize = "2147483647">
& Lt; readerquotas maxdepth = "2147483647"
Maxstringcontentlength = "2147483647"
Maxarraylength = "2147483647"
Maxbytesperread= "2147483647"
Maxnametablecharcount = "2147483647" type = "parmname" text = "parmname"/>
<Reliablesession ordered = "true" inactivitytimeout = "00:01:00" enabled = "false"/>

<Security mode = "NONE">
<Transport clientcredentialtype = "Windows" protectionlevel = "encryptandsign"/>
<Message clientcredentialtype = "Windows"/>
</Security>
</Binding>
</Nettcpbinding>

<Behavior name = "jxsoft. jplan. wcfservice. behavior">
<Servicethrottling maxconcurrentcils = "1000" maxconcurrentinstances = "1000" maxconcurrentsessions = "1000"/>
<Servicemetadata/>
<Servicedebug includeexceptiondetailinfaults = "true"/>
<Datacontractserializer maxitemsinobjectgraph = "6553600"/>
</Behavior>

11
By default, many bindings in WCF are secure. Generally, either transport (tcpbinding) or message (wshttpbinding) security mode is used. In addition, authentication is enabled for the client.

<Security mode = "NONE">
<Transport clientcredentialtype = "NONE"/>
<Message clientcredentialtype = "NONE"/>

12 The interface in WCF cannot use static methods, but you can repackage a layer in the implementation class.

13 http://blog.chinaitlab.com/html/30/104830-163124.html

14
Two methods
Public static class extensions
{
Public static void closeconnection (this icommunicationobject myserviceclient)
{
If (myserviceclient. State! = Communicationstate. Opened)
{
Return;
}
Try
{
Myserviceclient. Close ();
}
Catch (communicationexception ex)
{
Debug. Print (ex. tostring ());
Myserviceclient. Abort ();
}
Catch (timeoutexception ex)
{
Debug. Print (ex. tostring ());
Myserviceclient. Abort ();
}
Catch (exception ex)
{
Debug. Print (ex. tostring ());
Myserviceclient. Abort ();
Throw;
}
}
}

Another way is to write a partial class in wcfserviceclient, And Then inherit the idispose

Disable it in the dispose method. Then use using at the front end

 

15
In addition, if servicedebugbehavior is enabled (the includeexceptiondetailinfaults switch is enabled), the WCF Service only encapsulates General CLR exceptions (non-faultexception. For faultexception, no operation will be performed.

 

16 A session service. First, 1 binging is a 2 sessionmode that can be provided and must adapt to 3 persessions. If it is a percall, It is not suitable. 4 there cannot be transactions, and there must be a data channel (Security and reliablesession have a configuration)

17. Do not use generics in data contracts. It would be very strange to name it in that way. If there is no problem in the operation contract.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.