What is the best way to convert/cast a SoapUnknownHeader to a clas

M

Michael

In my ProcessMessage function inside my SoapExtension, I need to convert the
incoming SoapUnknownHeader to the original class.

Code snippet currently looks like the following:
foreach (SoapUnknownHeader header in message.Headers)
{
if (header.Element.Name.CompareTo("ScCredentials")==0)
{
ScCredentials credentials = (ScCredentials) ((SoapHeader)header);

I get an invalid cast exception with the above. Incoming XML appears to be
correct...I must be over looking something.

I thought about using the XMLSerializer...but I am thinking there should be
a light weight way of doing this.

TIA
 
D

Dan Rogers

The easiest way to do this is to tell the serializer about your custom
header at coding time.

If you search for SoapHeader on MSDN, you'll find some great examples of
creating custom header classes and then using them in your web services.
If you already have the header class created, all you have to do is tell
the web service about the header so that it will be made available to you
programatically at the time your web method is invoked.

Hope this helps,

Dan Rogers
Microsoft Corporation
--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top