SoapContext Class
Assembly: Microsoft.Web.Services2 (in microsoft.web.services2.dll)
The following example is a simple Xml Web service that returns various properties of a SoapContext . The example uses the Current method of the RequestSoapContext class to get the SoapContext .
using System; using System.ComponentModel; using System.Web.Services; using Microsoft.Web.Services2; using Microsoft.Web.Services2.Security; namespace www.cohowinery.com { public class YourWebService : System.Web.Services.WebService { public YourWebService() { // This call is required by the ASP.NET Web Services Designer InitializeComponent(); } //Required by the Web Services Designer private IContainer components = null; private void InitializeComponent() { } [WebMethod] public string ReturnSoapContextInfo() { string message; try { SoapContext requestContext = RequestSoapContext.Current; // Verifies that a SOAP request was received. if (requestContext == null) { throw new ApplicationException("Either a non-SOAP request was" + "received or the WSE is not properly installed for " + "the Web application hosting the XML Web service."); } message = string.Format("ContentType = {0}", requestContext.ContentType); message += string.Format("Attachments.Count = {0}", requestContext.Attachments.Count ); message += string.Format("Attachments.Envelope.Body= {0}", requestContext.Envelope.Body ); return message; } catch(Exception exc) { message = string.Format("ERROR = {0}", exc.Message); return message; } } } }
Web service clients access their SoapContext using the RequestSoapContext and ResponseSoapContext properties of a WebServicesClientProtocol . Web services access their SoapContext using the static Current property of the RequestSoapContext and ResponseSoapContext classes. The SoapContext can also be obtained using the SoapContext property of a SoapWebResponse or SoapWebRequest .
To access the current SOAP context from within a custom filter, use the Microsoft.Web.Services2.SoapContext.Current property. The Microsoft.Web.Services2.RequestSoapContext.Current and Microsoft.Web.Services2.ResponseSoapContext.Current properties are not valid during pipeline processing when customs filters execute.