NET asynchronous call Webserver, net asynchronous webserver

Source: Internet
Author: User

NET asynchronous call Webserver, net asynchronous webserver

Previously, a colleague ran to ask me a bunch of multithread asynchronous calls to the Sap service and then suddenly shut down the process. He also said that he would set a loop to judge the call result, I was confused, but I obviously felt that his design was getting farther away... no car is returned in the remote mountainous area! However, as a newcomer to the company, I have clarified his needs because he does not know how to call webserver asynchronously, or does not know how to call callback function event structures, or sap is too lazy, no response can be given or returned. I don't understand the problems with NET development and SAP development. It's actually a problem!

 

On this premise, three or four people came to me and asked me what I had previously done to call the SAP Service asynchronously. In fact, I prefer synchronization, haha ·~ In addition, the information on the Internet is more general, so we do not pay attention to thinking and analysis of events on the official website. It is not conducive to the learning of small students like me ~~

Then I told him about the design mistake. I hate people who need to send their source code to the other party, but forget it. Everything is wrong in the design direction, one thing that can be clearly understood by others is that this person's description is very complicated, and there will be a lot of inexplicable things in the chaotic code processing logic.

 

I have experienced the growth of several teams before and after, and I have encouraged myself to understand the thinking of most teams in the team, so that they can better complement each other and do a good job in this team, but this team is not my team either, I tried my best to help you ~

 

The following are examples of delegate events:

OnBeginHelloWorldDelegate, onEndHelloWorldDelegate, onHelloWorldCompletedDelegate: Start, end, submit.

Net underlying call delegate:

ClientBase <TChannel>. BeginOperationDelegate; ClientBase <TChannel>. EndOperationDelegate; SendOrPostCallback: method to be called when it is scheduled to the synchronization Context

  

So asynchronous if you want to process the relationship between callback and batch calls, it is very easy to use the HelloWorldAsync overload function (string arg, object userState) userState will be taken from InvokeAsync, TestWebService. HelloWorldCompletedEventArgs e:

Call code: testwebservice. HelloWorldAsync (para. name, para); ---- para indicates the callback entity to be called.

 

Therefore, with the binding of these delegate events, reloads can be used to handle any callback or the end of the execution, you can also expand more complex delegate event callbacks in the service namespace;

 

 

Case Analysis:

. Net asynchronously calls the service and delegates the callback for collection. First, the service to be called does not return any results. Second, we need to grasp any execution results and do not rule out that the service of the other party is closed. Third, it must be asynchronous and multithreading (technically blind, I think it is good to hear asynchronous multithreading ).

Solution 1: Construct a delegate from the proxy class for callback, and callback the delegate event in the async function. From the beginning to the end, we have a set of declaration of delegated events. We can do anything we love about parameters. Define a delegate SendOrPostCallbackTwo in system. threading and an EventhandlerTwo delegate in System,

Declare event_A in the Service proxy generation class and construct the OnHelloWorldCompletedTwo (object state, object entity) function,

 

Append event judgment or implementation in the asynchronous call function HelloworldAsync,

Perform the constructor in helloworldcompletedeventarstwo:

Proxy call method:

Callback Function ProcessCompleteThree:

The Declaration of the prepared thread pool delegate class:

 

Thread Pool call:

In fact, this solution is implemented using delegated events, but some people study the mechanism of the proxy object introduced by the web service if it is messy, generally, callback construction is not so troublesome.

 

Solution 2 is to use the constructor of the delegate class of the thread pool to bring in parameters so that the primary key can be used for business processing during callback.

 

Solution 3 also uses e. UserState, which is automatically generated in the Completed of the Service generation object. The principle is the same as solution 1.

Not to mention.

 

For learning purposes only. For more information, see the source.

 

Related Article

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.