This gets a bit complicated but it's perfectly doable.
You have to know the SOAPAction you want to take. If you don't you can't make the request. If you don't want to set this up manually you can add a service reference to Visual Studio but you will need to know the services endpoint.
The code below is for a manual SOAP request.
// load that XML that you want to post
// it doesn't have to load from an XML doc, this is just
// how we do it
XmlDocument doc = new XmlDocument();
doc.Load( Server.MapPath( "some_file.xml" ) );
// create the request to your URL
HttpWebRequest request = (HttpWebRequest)WebRequest.Create( Your URL );
// add the headers
// the SOAPACtion determines what action the web service should use
// YOU MUST KNOW THIS and SET IT HERE
request.Headers.Add( "SOAPAction", YOUR SOAP ACTION );
// set the request type
// we user utf-8 but set the content type here
request.ContentType = "text/xml;charset="utf-8"";
request.Accept = "text/xml";
request.Method = "POST";
// add our body to the request
Stream stream = request.GetRequestStream();
doc.Save( stream );
stream.Close();
// get the response back
using( HttpWebResponse response = (HttpWebResponse)request.GetResponse() )
{
// do something with the response here
}//end using
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…