Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - Exploring the Header in the WSE 2.0 SoapEn...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Exploring the Header in the WSE 2.0 SoapEnvelope Class
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2007-01-15

    Table of Contents:
  • Exploring the Header in the WSE 2.0 SoapEnvelope Class
  • SOAP Headers
  • Code for the Public Class
  • Running the Code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Exploring the Header in the WSE 2.0 SoapEnvelope Class - Code for the Public Class


    (Page 3 of 4 )

    As noted previously, here is the code:

    Imports System Imports System.Web.Services.Protocols Namespace
    SoapHeader Public Class jhdr Inherits
    System.Web.Services.Protocols.SoapHeader Public UserName As
    String End Class End Namespace

    The code for the SopHdr.asmx is shown here:

    Imports System.Web.Services.Protocols Imports Microsoft.Web.Services2 Namespace SoapHeader <System.Web.Services.WebService(Namespace:="http://tempuri.org/Hdrs/
    SopHdr")> _ Public Class SopHdr Inherits System.Web.Services.Protocols.SoapHeader Public myHeader As New jhdr #Region " Web Services Designer Generated Code " <WebMethod(), SoapHeader("myHeader")> _ Public Function TestHdr() As String Dim sen1 As New Microsoft.Web.Services2.SoapEnvelope myHeader.UserName = "mysorian" sen1.SetBodyObject("OK") sen1.InnerXml = "<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:Header/> <soap:Body> </soap:Body> </soap:Envelope>" sen1.Header.InnerXml = myHeader.UserName Try 'Return sen1.Header.IsEmpty Return sen1.Header.OuterXml Catch ex As SoapHeaderException Return ex.Message End Try End Function End Class End Namespace

    The following items are to be noted:

    WSE2.0 is properly referenced by the imports statement. The statement regarding the inheritance from the System.Web.Services.protocols is included. An instance of the class jhdr is included. Also the SoapHeader reference to the jhdr class is referenced in the Web Method.

    With the above in place, a Public function is scripted to get the SoapEnvelope's Header information using the above code. First of all a reference to the SoapEnvelope from WSE2.0 is instantiated with sen1. The SoapEnvelope should have a Body element; hence, a dummy body ["OK"] is set using the SetBodyObject method. Also the root element must be present; this is supplied by the SoapEnvelope's InnerXML setting.

    Look at the complete string of the SoapEnvelope. You will observe that an empty SoapHeader element is added. With this preliminary preparation, the method can take all this information and return the SoapEnvelope's header from the web service. The commented return should produce a false since the header is not empty. Errors in the SoapHeader can be thrown as SoapErrorException. For example, if you were to drop the <Soap:Header/> element in the SoapEnvelope string an exception would be thrown.

    More Windows Scripting Articles
    More By Jayaram Krishnaswamy


       · Soap header although optional is important as it can carry information to be...
     

    WINDOWS SCRIPTING ARTICLES

    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH
    - Advanced Word Object Scripting
    - Reading and Printing Word Documents in WSH
    - Scripting Microsoft Word
    - Using WSH to Catalog MP3 Files
    - Reading MP3 ID3 Tags in WSH
    - A Brief Look at Menus in WPF
    - More Examples of Simplified Image Processing...
    - Completing a WPF To-Do List Application
    - Simplified Image Processing in GDI+





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT