A preliminary analysis of the principle and process of WebService request transmission in asp.net

Source: Internet
Author: User
Tags constructor httpcontext soap xmlns


Requirements: As a service provider, you need to monitor each client that invokes webservice. The information that needs to be monitored is roughly as follows: the IP of the client, which method of which class the client invokes.



So I spent some time on the asp.net of the WebService machine made a little exploration.



Solution:



Write a base class for all the WebService interfaces in the interface project, in the constructor method of the base class, to  you want by analyzing the HttpContext.Current.Request.



1.ip can be obtained by HttpContext.Current.Request.UserHostAddress



2. Which method and parameter can be sent through the analysis HttpContext.Current.Request.InputStream



This is the content of the InputStream I output using the following code:


<?xml version= "1.0" encoding= "Utf-8"?>
<soap:envelope xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd= "Http://www.w3.org/2001/XMLSchema" >
<soap:Body>
  <mytestmethod xmlns= "http://tempuri.org/" >
    <msg>abcd</msg>
  </MyTestMethod>
</soap:Body>
</soap:Envelope>


Did you see that? The method called is Mytestmethod, the parameter is MSG, the value is ABCD



The following is the process of testing:



Give the conclusion first:



When a asp.net program adds a reference to WebService, the client generates the proxy proxy class.



The calling code for the client is generally similar to this:



Ws. Service1 s = new WSWeb.ws.Service1 ();



S.helloworld ();



S.mytestmethod ("sssssssssssssttttt");



1. In WS. Service1 s = new WSWeb.ws.Service1 (); When this line is run, the server-side constructor is not invoked, but instead the constructor method of the locally generated proxy class is invoked.



2. Only when running this row: S. HelloWorld (), the method and parameters will be formed soap, bound to HTTP, sent to the server side. At this point, you call the server-side construction method, and then call the server-side HelloWorld



Run line 3rd S. Mytestmethod ("Sssssssssssssttttt"), this is the case, will first adjust the server-side construction method, and then invoke server-side Mytestmethod.





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.