当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Restrict requests made by Visual Studio generated soap client to single thread

问题描述:

I am testing a SOAP service using a client generated in VS2010 via "Add Service Reference".

I am running tests in parallel (c. 10 threads) and this has exposed some DB locking issues in the system under test. However, this is not going to be fixed straight away and I don't want my functional tests failing due to this problem.

As a result I have reduced by test threads to 1, and as expected I do not see the locking issue, however, this obviously makes my test suites a great deal slower. Therefore I was wondering if it is possible to use client configuration to restrict the client to only make one request concurrently?

网友答案:

Its not the soap client that needs to be restricted its the calling code. A Soap call will be performed in which ever thread it is being made from. If you have a problem with multiple threads this is because you have multiple threads in your code, or you are trying to make additional service calls or updating something in a callbacks without understanding what thread you are in.

Depending on the problem you have many solutions which could include:

  1. Remove the multi-threading from your application, don't use callbacks and don't fire up additional threads.

  2. or ideally Make sure you dispatch back to the UI when appropriate, understand which thread you are in so you fix the underlying locking problem

http://msdn.microsoft.com/en-us/library/ms591206.aspx

    Me.Dispatcher.BeginInvoke(Sub()
                                  ' This will be executed on the UI Thread
                              End Sub)

It would be nice (and very useful) to have the code in question..... in your question. Which version of .net your using and what your app is written in (Asp.net, WinForms?) would also help get some context.

NB: Sample code in vb.net but you get the idea ;p

分享给朋友:
您可能感兴趣的文章:
随机阅读: