473,395 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Cannot access Soapheader in SoapExtension

I have a problem accessing my custom SoapHeader from a SoapExtension. My
extension has no compile time reference to the class derived from
SoapHeader, so how can cast it into a SoapHeader of the correct type?
Thanks,

Andy
Sep 6 '06 #1
10 2191
"Andy Kendall" <no*************@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>I have a problem accessing my custom SoapHeader from a SoapExtension. My
extension has no compile time reference to the class derived from
SoapHeader, so how can cast it into a SoapHeader of the correct type?
XML.

John
Sep 6 '06 #2
Care to elaborate? Do you mean XML deserialization?

"John Saunders" <john.saunders at trizetto.comwrote in message
news:uH**************@TK2MSFTNGP03.phx.gbl...
"Andy Kendall" <no*************@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
I have a problem accessing my custom SoapHeader from a SoapExtension. My
extension has no compile time reference to the class derived from
SoapHeader, so how can cast it into a SoapHeader of the correct type?

XML.

John


Sep 7 '06 #3
"Andy Kendall" <no*************@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Care to elaborate? Do you mean XML deserialization?

"John Saunders" <john.saunders at trizetto.comwrote in message
news:uH**************@TK2MSFTNGP03.phx.gbl...
>"Andy Kendall" <no*************@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>I have a problem accessing my custom SoapHeader from a SoapExtension. My
extension has no compile time reference to the class derived from
SoapHeader, so how can cast it into a SoapHeader of the correct type?

XML.
Ok, I apologize. I thought I had a SOAP Extension which was accessing the
headers as XML. I was mistaken, it accesses them as a SoapHeader-derived
object.

So, to your question: I don't understand how a class, "A", without a
compile-time reference to another class, "B", could cast an object to an
instance of class "B". This question is independent of SOAP Extensions and
Headers. In fact, once it had been cast to class "B", how would class "A"
reference the methods, fields, etc., of class "B" if it has no compile-time
reference to it?

I think more detail is required.

John
Sep 7 '06 #4
Well, given that only xml data is being transferred between client and
server, I wondered if it was possible to create an identical class
definition and cast it into that. After all, normally when you create a web
service and a client VS generates the server and client proxy class and it
works fine - these two classes are not the same - i.e. No binary .dll or
similar has to be shared between client and server but you can use
DirectCast on the base class as if they were.

I tried creating an identical SoapHeader class in my SoapExtension project
in an identical namespace but it complains with "invalid cast" It makes me
wonder how the runtime knows that the xml representaion of my soapHeader
class coming over the wire is not based on the one defined in my
SoapExtension priject but on the SoapHeader defined on the web service
instead - does the deserialised XML have some kind of guid or reference to
the assembly?

I can do what I need to do by adding a reference to the web service .dll
file into my SoapExtension project, but I would rather not have that
dependancy. I also suspect you can do it with manual deserialisation (?) I
just wondered if there was an easier way.

Incidentally, I also notice there is no way to access the raw XML from the
base SoapHeader class, otherwise I would have just used that.

"John Saunders" <john.saunders at trizetto.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
"Andy Kendall" <no*************@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Care to elaborate? Do you mean XML deserialization?

"John Saunders" <john.saunders at trizetto.comwrote in message
news:uH**************@TK2MSFTNGP03.phx.gbl...
"Andy Kendall" <no*************@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
I have a problem accessing my custom SoapHeader from a SoapExtension.
My
extension has no compile time reference to the class derived from
SoapHeader, so how can cast it into a SoapHeader of the correct type?

XML.

Ok, I apologize. I thought I had a SOAP Extension which was accessing the
headers as XML. I was mistaken, it accesses them as a SoapHeader-derived
object.

So, to your question: I don't understand how a class, "A", without a
compile-time reference to another class, "B", could cast an object to an
instance of class "B". This question is independent of SOAP Extensions and
Headers. In fact, once it had been cast to class "B", how would class "A"
reference the methods, fields, etc., of class "B" if it has no
compile-time
reference to it?

I think more detail is required.

John


Sep 7 '06 #5
"Andy Kendall" <no*************@hotmail.comwrote in message
news:ez**************@TK2MSFTNGP03.phx.gbl...
Well, given that only xml data is being transferred between client and
server, I wondered if it was possible to create an identical class
definition and cast it into that. After all, normally when you create a
web
service and a client VS generates the server and client proxy class and it
works fine - these two classes are not the same - i.e. No binary .dll or
similar has to be shared between client and server but you can use
DirectCast on the base class as if they were.
Ok, now, note that I haven't quite tried what I'm going to suggest. The
closest I've come to this had to do with SOAP faults.

If the SOAP Extension and the Web Service both access the same SOAP header,
then the definition of the SOAP Header should be in a common place. Perhaps
you can separate out the schema for the SOAP Header, and put the schema,
along with the code generated from the schema, into a separate project. That
project would "own" the piece of schema which defines these SOAP Headers.

This project would be referenced by the web service and by the SOAP
Extension.

I've done something similar with SOAP faults, which needed to be accessed
both by one web service and by some code common amongst several web
services. The schema, the generated classes, and the code to create
instances of the SOAP faults was all located in the common project.

I hope this helps. Please let us know how it works out. I don't yet have a
SOAP Header which is shared, but that might happen.

John
Sep 7 '06 #6
Thanks for the reply John,

I think what you suggest is the ideal way forward, however, our situation is
that the SoapExtension in question is just a temporary fix to be applied to
an existing live webservice. On the next build cycle, I think we will
seperate out as you suggest. As our SoapHeader was defined as public,
luckily I have been able to add a reference to the webservice .dll file so
it gets round the problem.

I'm still intrigued as to how visual studio/ASP.NET does it though. I mean,
in a normal visual studio scenario, you create you webservice with any
soapheaders, then you add a reference to that service from a client app. The
proxy classes generated on the client for the soapheaders are completly
different classes from the soapheader classes on the server and yet you can
create instances of them on the client, send them accross the wire and cast
them back into the correct type on the server and it all works swimmingly.
How does the runtime know not to throw an invalid cast exception?
"John Saunders" <john.saunders at trizetto.comwrote in message
news:e0**************@TK2MSFTNGP05.phx.gbl...
"Andy Kendall" <no*************@hotmail.comwrote in message
news:ez**************@TK2MSFTNGP03.phx.gbl...
Well, given that only xml data is being transferred between client and
server, I wondered if it was possible to create an identical class
definition and cast it into that. After all, normally when you create a
web
service and a client VS generates the server and client proxy class and
it
works fine - these two classes are not the same - i.e. No binary .dll or
similar has to be shared between client and server but you can use
DirectCast on the base class as if they were.

Ok, now, note that I haven't quite tried what I'm going to suggest. The
closest I've come to this had to do with SOAP faults.

If the SOAP Extension and the Web Service both access the same SOAP
header,
then the definition of the SOAP Header should be in a common place.
Perhaps
you can separate out the schema for the SOAP Header, and put the schema,
along with the code generated from the schema, into a separate project.
That
project would "own" the piece of schema which defines these SOAP Headers.

This project would be referenced by the web service and by the SOAP
Extension.

I've done something similar with SOAP faults, which needed to be accessed
both by one web service and by some code common amongst several web
services. The schema, the generated classes, and the code to create
instances of the SOAP faults was all located in the common project.

I hope this helps. Please let us know how it works out. I don't yet have a
SOAP Header which is shared, but that might happen.

John


Sep 8 '06 #7
"Andy Kendall" <no*************@hotmail.comwrote in message
news:uM**************@TK2MSFTNGP04.phx.gbl...
Thanks for the reply John,

I think what you suggest is the ideal way forward, however, our situation
is
that the SoapExtension in question is just a temporary fix to be applied
to
an existing live webservice. On the next build cycle, I think we will
seperate out as you suggest. As our SoapHeader was defined as public,
luckily I have been able to add a reference to the webservice .dll file so
it gets round the problem.

I'm still intrigued as to how visual studio/ASP.NET does it though. I
mean,
in a normal visual studio scenario, you create you webservice with any
soapheaders, then you add a reference to that service from a client app.
The
proxy classes generated on the client for the soapheaders are completly
different classes from the soapheader classes on the server and yet you
can
create instances of them on the client, send them accross the wire and
cast
them back into the correct type on the server and it all works swimmingly.
How does the runtime know not to throw an invalid cast exception?
It doesn't know. The cast is not invalid. It does not send instances across
the wire. It serializes a client instance, sends it across the wire, then
deserializes it into a totally separate server instance, which is of a type
unrelated to the type of the client instance.

No objects are ever transmitted in web services. Just XML.

John
Sep 8 '06 #8
Sure, but then whats different about that scenario and the one I first tried
where I had an identical class definition (with same namespace) in my soap
extension project?

I know there must be something in the serialised xml telling the runtime
that the serialised soapheader represents the soapheader class defined in my
web service and not the (identical) one defined in the soapextension
assembly - but I don't know what it is.
>
It doesn't know. The cast is not invalid. It does not send instances
across
the wire. It serializes a client instance, sends it across the wire, then
deserializes it into a totally separate server instance, which is of a
type
unrelated to the type of the client instance.

No objects are ever transmitted in web services. Just XML.

John


Sep 8 '06 #9
"Andy Kendall" <no*************@hotmail.comwrote in message
news:uR**************@TK2MSFTNGP06.phx.gbl...
Sure, but then whats different about that scenario and the one I first
tried
where I had an identical class definition (with same namespace) in my soap
extension project?

I know there must be something in the serialised xml telling the runtime
that the serialised soapheader represents the soapheader class defined in
my
web service and not the (identical) one defined in the soapextension
assembly - but I don't know what it is.
I'm not sure of the step by step details, but it's something like this:

1) IIS receives a request directed at some file with a .asmx extension
2) Since there's a sctipt mapping between that extension and ASP.NET, the
request is sent to the ASP.NET worker process
3) The worker process looks at the file extension, and maps it to a
HttpHandler subclass, in this case, WebServiceHandler (I think)
4) WebServiceHandler opens the .asmx file and, based on its contents,
determines which WebService-derived class to use.
5) Based on the metadata on this class, it matches the incoming SOAP message
to a WebMethod
6) Based on the metadata on this WebMethod, it deserializes the SOAP message
6a) You have one or more [SoapHeader] attributes on your WebMethods, right?
6b) Each SoapHeader attribute refers to a public field in your WebService.
6c) The field has a type and maybe other attributes, which guide
deserialization of any matching SOAP headers in the message

So, no magic, just a bit of work going on in the background.

John
Sep 8 '06 #10
John, Thanks for the reply. I have found some more information which answers
my query:

When you specifiy a soapHEader on a web method you use the SoapHeader
attribute specifiying the name of your SoapHeader derived class. It doesn't
matter what namespace the proxy or server class lives in because it is just
plain serialised/deserialised, as you quite rightly say - there is no magic
going on.

What was confusing me was why when I tried to access the soapHeader from a
soap extension I couldn't cast into the correct type of soapHeader unless I
referenced the original web service project .dll.

I now understand my mistake. In the web service, ASP is handling the
serialising, but in the soap extension ASP has only deserialised the headers
to the base type i.e. SoapHeader and not the original derived soapHeader.
This of course makes sense and what I was trying to do was just a plain
invalid cast exception.
Cheers for your help
"John Saunders" <john.saunders at trizetto.comwrote in message
news:uF**************@TK2MSFTNGP03.phx.gbl...
"Andy Kendall" <no*************@hotmail.comwrote in message
news:uR**************@TK2MSFTNGP06.phx.gbl...
Sure, but then whats different about that scenario and the one I first
tried
where I had an identical class definition (with same namespace) in my
soap
extension project?

I know there must be something in the serialised xml telling the runtime
that the serialised soapheader represents the soapheader class defined
in
my
web service and not the (identical) one defined in the soapextension
assembly - but I don't know what it is.

I'm not sure of the step by step details, but it's something like this:

1) IIS receives a request directed at some file with a .asmx extension
2) Since there's a sctipt mapping between that extension and ASP.NET, the
request is sent to the ASP.NET worker process
3) The worker process looks at the file extension, and maps it to a
HttpHandler subclass, in this case, WebServiceHandler (I think)
4) WebServiceHandler opens the .asmx file and, based on its contents,
determines which WebService-derived class to use.
5) Based on the metadata on this class, it matches the incoming SOAP
message
to a WebMethod
6) Based on the metadata on this WebMethod, it deserializes the SOAP
message
6a) You have one or more [SoapHeader] attributes on your WebMethods,
right?
6b) Each SoapHeader attribute refers to a public field in your WebService.
6c) The field has a type and maybe other attributes, which guide
deserialization of any matching SOAP headers in the message

So, no magic, just a bit of work going on in the background.

John


Sep 22 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: justin_sun | last post by:
All the sample code that I can find on SoapHeader is at least one level down within a root node. However, I'm working on a project needs to create a soap header like this: <SOAP-ENV:Header>...
1
by: Sridhar, S. | last post by:
Hi all, I am working on a project which requires webservices to log information about requests that are sent to it. I have written a SoapExtension that logs client information when a request is...
3
by: Trevor Pinkney | last post by:
Hi, Is it possible to reference a custom SoapExtension instance from within a WebMethod? I have a SoapExtension used by several web-services for generic logging. The SoapExtension logs the...
2
by: Mike Fiedler | last post by:
On a client web services request, I have a SoapExtension that is adding a header to the message in the BeforeSerialize stage. If the Web Service request is for an operation with...
3
by: Lucvdv | last post by:
I have a SOAP client, built upon proxy code generated by wsdl.exe from a wsdl file that was provided by the creator of a webservice. Now I want to log the raw XML that is being sent and received,...
2
by: lprisr | last post by:
Hi, I have double byte characters in the content that I am returning using Web Services. However, the encoding in the xml file returned by Web Services is utf-8 and I am unable to read the...
0
by: thatsMaBoy | last post by:
Hi, I have a VB.NET 2003 web service client (EXE) that makes use of a SOAPExtension class. The client calls a web service that returns a SOAP message containing MIME encoded files. The...
3
by: Peter van der veen | last post by:
Hi In my porject i use a custom header to be added to the SOAP message. I added the the custom SOAP header to the follwoing function which is in the proxy class. But when invoking the proxy...
0
by: Fred | last post by:
I am trying to build a consumer to a webservice which use soapheader. I am using Visual Studio 2003. Please see the wsdl-file below. Why is it that the SOAPHEADER is empty when I use it int the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.