Exploring the SoapEnvelope Class in WSE2.0 - LoadXML and InnerText Properties
(Page 4 of 5 )
The following code creates a web service which looks at the inner text property of a SoapEnvelope:
Imports System.Web.Services
Imports Microsoft.Web.Services2
<System.Web.Services.WebService(Namespace :=
"http://tempuri.org/WSE2_1/Props")> _
Public Class Props
Inherits System.Web.Services.WebService #Region
" Web Services Designer Generated Code "
[author's note: this code has been removed for clarity]
#End Region <WebMethod()> _
Public Function InTxt() As String
Dim sen1 As New Microsoft.Web.Services2.SoapEnvelope
Try
sen1.LoadXml("<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>
<nom>United States</nom>
</soap:Body></soap:Envelope>")
Return sen1.InnerText
Catch ex As Exception
Return ex.Message
End Try
End Function End Class
We shall only concentrate on some of the important items highlighted in blue in the code without concerning ourselves too much with the designer created code. The second line below shows that the proper reference to WSE2.0 has been made.Imports System.Web.Services
Imports Microsoft.Web.Services2
Most of the properties and methods will be explored in this WebMethod template called InTxt(). This will actually look at the inner text property of the SoapEnvelope. The SoapEnvelope constructor admits of the NEW method and therefore a SoapEnvelope, sen1, is declared using the New keyword.
Once declared it is assigned a value which is appropriate for a SoapEnvelope document as shown. In the above code, the LoadXML() method is used to load the SoapEnvelope. The method's return is set to the inner text property of the SoapEnvelope that was loaded. Build the solution and right click the Props.asmx to click on View in Browser. This brings up the following browser screen:

The InTxt is the method of the web service can be tested by clicking the link which brings up the following (partially shown here):

The method can be tested by clicking the Invoke button in the browser. The result is shown again in the browser as shown:

This is the SoapEnvelope's InnerText property.
Next: Body Property and SetBodyObject() method >>
More Windows Scripting Articles
More By Jayaram Krishnaswamy