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.