Home > SOA Tips > .NET Developer > More on SOAP extensions
SOA Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

.NET DEVELOPER

More on SOAP extensions


Bob Tabor
10.21.2002
Rating: -4.67- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


In a previous tip, I explained how SOAP Extensions allow you to plug in and capture/manipulate the SOAP message in ASP.NET as it travels through the ASP.NET Web service chain of events -- from IIS to the ASP.NET ISAPI extension, through the HTTP modules down to the HTTP Handler. I also explained how there are four events (BeforeDeserialize, AfterDeserialize, BeforeSerialize and AfterSerialize) that allow you to inspect or modify the SOAP request message before/after it is deserialized into an object, and before/after the response object is turned back into a SOAP message. Now, I give you the code for the SoapLogger utility. This source code uses some pretty advanced features of .NET, such as the creation of custom attributes, manipulation of memory and file streams, and inheriting and overriding .NET Framework classes and methods (respectively) to implement your own functionality. To use this example, do the following:

  1. Create a new C# class library project called "SoapLogger".
  2. Download the source code and paste it into the Class1.cs file that was provided by Visual Studio.NET when you created the new project. Be sure to remove any existing code from that file before pasting this code into it.
  3. Compile the project. It will create a new assembly in the bin directory of your project called SoapLogger.dll
  4. Open the Web services project you want to add logging to. Open the actual ASMX file (or rather, its code behind file .cs or .vb).
  5. Add a reference to the SoapLogger.dll by right-clicking the project name in the solution explorer and selecting "Add reference..." and the Add Reference dialog will appear.
  6. Find your SoapLogger assembly in the list (or use the browse feature) and create a reference to the component.
  7. Add an attribute to the Web Method you want to log. For example, I used the following code in the method signature to log the results of the UpdateAffiliateDetail Web Method:

    (Notice the underscores in VB.NET!)

    Alternatively, you can send in a location if you don't like the default location and name using a property of the SoapLogger attribute:

  8. Compile and test your Web service. Once you do, you will see a log file that contains the SOAP messages for each time your Web Method is called.

Here's the C# code:

Notice that the SoapLogger class derives from the SoapExtension class. This is how you "plug into" the architecture of the HTTP Handler for Web services. Then, you must override several methods, such as Initialize, GetInitializer (allows you to retrieve the properties of the attribute, or set default values), ChainStream (allows you to copy off the memory stream for processing) and most importantly the ProcessMessage method, that allows you to determine which stage the SOAP request/response is currently in. If you take a look in the example above in the ProcessMessage method, I only test for two ...


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
SOAP
Denmark is first to adopt Universal Business Language
XML-based financial standard gets new support
SOAP test tool adds WS-Security, MIME support
Survey: IT spending back from the dead
WASP Server adds to XML Schema support
IBM, Microsoft on opposite sides of standards fence
WS orchestration 'power struggle' under way, IDC says
Internet millionaire gives integration a whirl
WS-I accepting comments on latest efforts
Grand Central adds directory to integration service

Microsoft .NET Web services
Microsoft preps .NET 4.0 - framework improves on REST, MVC, JQuery support
How do I balance throughput requirements and interoperability?
APM software traces transactions across tiers, technologies
How you can learn M Grammar for Oslo modeling
Legacy modernization opens Windows for publisher
Former .NET Web developers ride Ruby and Rails application framework
Microsoft Oslo at PDC: Dial 'M' for modeling language
Yahoo proxy fight looms
New Microsoft site for architects
LAMP coders go hybrid route
Microsoft .NET Web services Research

.NET Developer
Programming Indigo
DataSets and Web services don't mix
Security in .NET 2.0
Tracking down managed memory leaks
Handling exceptions in .NET
.NET Compact Framework graphics
The Data Access Application Block
A great .NET resource: .Net2TheMax
Delegates vs. interfaces in .NET
Project structure best practices

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
Common Language Infrastructure  (SearchSOA.com)
Visual J#  (SearchSOA.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


SoapMessageStages -- BeforeDeserialize and AfterSerialize. Why is that? Because this is when the message is actually a SOAP message, and is not in its object form.

You can extend this sample and build all sorts of inspection and logging into your Web service applications. This should give you plenty of meat to cut your teeth on. Until next time...


About the Author

[IMAGE]Robert Tabor is a Microsoft Certified Professional in Visual Basic with over six years of experience developing n-tier Microsoft-centric applications for some of the world's most prestigious companies and consulting organizations, such as Ernst & Young, KPMG, Cambridge Technology Partners, Sprint, American Heart Association, and the Mary Kay Corporation. Bob is the author of Microsoft .NET XML Web services by Sams Publishing, and contributes to SoapWebservices.com and LearnVisualStudio.NET. He is currently working on initiatives within Mary Kay, the second largest eCommerce site in retail volume on the net, of how to utilize .NET within their e-business group.

Rate this Tip
To rate tips, you must be a member of SearchSOA.com.
Register now to start rating these tips. Log in if you are already a member.




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



SOA Trends and Strategy - SOA Education, SOA Development, SOA Implementations
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2001 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts