Solution for unable to connect the client to the server in the WCF Project

Source: Internet
Author: User
Tags net time

The new project uses WCF to implement client-to-server communication. C/s architecture. The client uses winfrom. During the project trial run, many users complain that the system is always unable to log on normally.

View the log and find the following exception information:

System. ServiceModel. Security. MessageSecurityException: the other party receives an error that has not been processed or is incorrectly handled. For error code and details
See Internal FaultException. ---> System. ServiceModel. FaultException: at least one security token in the message cannot be verified.

The UserName security authentication method is used for WCF communication. The above exception is mostly caused by the time synchronization between the client and the server, the difference between the Binding client and the server provided by WCF can be 5 minutes.

The reason is found. Here is how to solve the problem. Most of the methods on the Internet are to use the command: net time \ IP address or server name/set/yes to synchronize the client time, the reason is as follows:

Through communication with users, it is found that many users intentionally advance or postpone the time for 10 minutes. Many reasons are not detailed.

Continue to find other solutions. On a foreign forum, you can use customBinding to modify the maximum allowed time deviation. Let's try it!

The configuration file before modification (some configuration sections are deleted) is as follows:
01
<System. serviceModel>
02
<Client/>
03
<Services>
04
<Service name = "userService">
05
<Endpoint address = "" binding = "wsHttpBinding" bindingConfiguration = "Binding_user"
06
Contract = "Iuser"/>
07
</Service>
08
<Bindings>
09
<WsHttpBinding>
10
<Binding name = "Binding_user">
11
<Security mode = "Message">
12
<Transport/>
13
<Message clientCredentialType = "UserName"/>
14
</Security>
15
</Binding>
16
</WsHttpBinding>
17
</Bindings>
18
</System. serviceModel>
1
After replacing wsHttpBinding with customBinding, the configuration file is as follows:
01
<System. serviceModel>
02
<Client/>
03
<Services>
04
<Service name = "userService">
05
<Endpoint address = "" binding = "customBinding" bindingConfiguration = "MyCustomBinding"
06
Contract = "Iuser"/>
07
</Service>
08
</Services>
09
<Bindings>
10
<CustomBinding>
11
<Binding name = "MyCustomBinding">
12
<TransactionFlow/>
13
<Security authenticationMode = "UserNameForSslNegotiated">
14
<SecureConversationBootstrap>
15
<LocalClientSettings maxClockSkew = "00:59:00"/>
16
<LocalServiceSettings maxClockSkew = "00:59:00"/>
17
</SecureConversationBootstrap>
18
<LocalClientSettings maxClockSkew = "00:59:00"/>
19
<LocalServiceSettings maxClockSkew = "00:59:00"/>
20
</Security>
21
<TextMessageEncoding>
22
<ReaderQuotas maxStringContentLength = "500000" type = "regxph" text = "yourobjectname"/>
23
</TextMessageEncoding>
24
<HttpTransport maxcompute edmessagesize = "10485760" maxBufferPoolSize = "524288"/>
25
</Binding>
26
</CustomBinding>
27
</Bindings>
28
</System. serviceModel>
1
Here, the maximum time deviation is changed to 59 minutes.
1
The above is only the server configuration file modified, which must be modified in the app. config file of the client. After the client configuration is modified as follows:
01
<System. serviceModel>
02
<Bindings>
03
<CustomBinding>
04
<Binding name = "MyCustomBinding" closeTimeout = "00:01:00"
05
OpenTimeout = "00:01:00" receiveTimeout = "00:10:00" sendTimeout = "00:01:00"
06
>
07
<TransactionFlow/>
08
<Security authenticationMode = "UserNameForSslNegotiated">
09
<SecureConversationBootstrap>
10
<LocalClientSettings maxClockSkew = "00:59:00"/>
11
<LocalServiceSettings maxClockSkew = "00:59:00"/>
12
</SecureConversationBootstrap>
13
<LocalClientSettings maxClockSkew = "00:59:00"/>
14
<LocalServiceSettings maxClockSkew = "00:59:00"/>
15
</Security>
16
<TextMessageEncoding>
17
<ReaderQuotas maxStringContentLength = "500000" type = "regxph" text = "yourobjectname"/>
18
</TextMessageEncoding>
19
<HttpTransport maxcompute edmessagesize = "10485760" maxBufferPoolSize = "524288"/>
20
</Binding>
21
</CustomBinding>
22
</Bindings>
23
<Client>
24
<Endpoint address = "http: // ********/user. svc" binding = "customBinding"
25
BindingConfiguration = "MyCustomBinding" contract = "Iuser"
26
Name = "CustomBinding_Iuser"/>
27
</Client>
28
</System. serviceModel>

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.