I recently wrote an SOA service and started to think that someone else can get my service address and then add a reference directly to use it. The result "Daniel" tells me that it cannot be used.
Let me write a SOAP call service example. I am a little confused, because I have never done this, so I got a Demo and learned it.
Learn the following:
There is an object in. Net: WebRequest, which can directly request the service method in the background.
Step 1
var webRequest = (HttpWebRequest)WebRequest.Create(this.Uri);webRequest.Headers.Add("SOAPAction", String.Format("\"{0}\"", this.SoapAction));webRequest.ContentType = "text/xml;charset=\"utf-8\"";webRequest.Accept = "text/xml";webRequest.Method = "POST";webRequest.Credentials = this.Credentials;
A:In the above Code, there is a SOAPAction, which is to access the service after you deploy the service in IIS, such:
The figure tells the user: SOAPAction: "http://tempuri.org/ProcessFlowRequest"
B:WebRequest. Credentials = this. Credentials;
Is the credential for calling the service
Step 2
After reading the preceding information, You Need To splice the SOAP information in the xml of the soap request.
<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> <soap:Body> <{0} xmlns='{1}'>{2}</{0}> </soap:Body></soap:Envelope>
Replace the corresponding information in the image with the position {X}, and the information is spliced!
Step 3
Var webRequest = (HttpWebRequest) WebRequest. create (this. uri); webRequest. headers. add ("SOAPAction", String. format ("\" {0} \ "", this. soapAction); webRequest. contentType = "text/xml; charset = \" UTF-8 \ ""; webRequest. accept = "text/xml"; webRequest. method = "POST"; webRequest. credentials = this. credentials; // write the request SOAP information using (var requestStream = webRequest. getRequestStream () {using (var textWriter = new StreamWriter (requestStream) {var envelope = SoapHelper. makeEnvelope (this. soapAction, this. arguments. toArray () ;}/// get the SOAP request and return the return webRequest. getResponse ();
This will get the XML returned by the request!
It is actually easy to know when it is used!
Example:
Baidu Network Disk: http://pan.baidu.com/s/1hquuXHa
Http://download.csdn.net/detail/hater22/7490147 (CSDN)