Changing namespace of a Soap Header


B

Brian Tyler

I have defined a soap header via the .NET framework

public sealed class MySoapHeader : SoapHeader
{
}

I can successfully send this header either from the client proxy or from the
web service itself. However, it seems that the "type" of the header is
always put into the namespace of the proxy or server. For example, under a
simple proxy, I get

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="http://tempuri.org"
xmlns:types="http://tempuri.org/encodedTypes"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<types:MySoapHeader id="h_id1"> ...

Note that it is put into the "types" ns, which is based on the ns of the
proxy.

How do I have the SOAP header have its own namespace? Something I can define
as part of the Soap header so it stays the same regardless of the proxy or
web service it is used with?

Thanks in advance

Brian
 
Ad

Advertisements

B

Brian Tyler

Christoph,

Thanks for the reply - I have good and bad news.

Turns out that your suggestion completely fixed the problem - IF - I have
the web service/proxy using document encoded SOAP. However, if I switch to
RPC encoded (and leave the XmlElement in place), then the SOAP header
switches to what you saw earlier. The namespace for the header is switched
to <ns of the web service>/encodedTypes.

I don't know if that is part of the spec or not - I have not really messed
with RPC encoding. However, due to a customer requirement I need to be able
to support both document and RPC.

Thoughts?

Brian


You can define the namespace of the header by attaching an XmlElement
attribute to the WebService class' header field:

[WebService(Namespace="http://www.bracketangles.net/ns")]
public class Service1 : System.Web.Services.WebService
{
// ...


[XmlElement(Namespace="http://www.bracketangles.net/headers")]
public MyHeader timeHeader;

[WebMethod]
[SoapHeader("timeHeader",
Direction=SoapHeaderDirection.InOut)]
//...

HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko

-----Original Message-----
From: Brian Tyler [mailto:[email protected]]
Posted At: Tuesday, January 18, 2005 1:49 PM
Posted To: microsoft.public.dotnet.framework.aspnet.webservices
Conversation: Changing namespace of a Soap Header
Subject: Changing namespace of a Soap Header

I have defined a soap header via the .NET framework

public sealed class MySoapHeader : SoapHeader
{
}

I can successfully send this header either from the client proxy or from
the
web service itself. However, it seems that the "type" of the header is
always put into the namespace of the proxy or server. For example, under a
simple proxy, I get

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="http://tempuri.org"
xmlns:types="http://tempuri.org/encodedTypes"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<types:MySoapHeader id="h_id1"> ...

Note that it is put into the "types" ns, which is based on the ns of the
proxy.

How do I have the SOAP header have its own namespace? Something I can
define
as part of the Soap header so it stays the same regardless of the proxy or
web service it is used with?

Thanks in advance

Brian
 
Ad

Advertisements

B

Brian Tyler

Thanks! I'm glad it is so consistent :)

Brian

Christoph Schittko said:
The familiy of serialization attributed that starts with Xml* does not
work for RPC encoded messages.

You'll have to substitute them for Soap* serialization attributes or add
the Soap* attributes if you share types between Document and RPC encoded
methods. You'll find a list of them at [0].

You don't set the namespace for your header element by attaching a
SoapElementAttribute, because that doesn't have a Namespace property
like the XmlElement does.


Instead, you attach a SoapType attribute to the HeaderClass:

[SoapType(Namespace="")]
public sealed class MyHeader : SoapHeader
{
// ...
}


HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko



[0]
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconattributesthat
controlsoapencodedserialization.asp?frame=true
-----Original Message-----
From: Brian Tyler [mailto:[email protected]]
Posted At: Wednesday, January 19, 2005 10:31 AM
Posted To: microsoft.public.dotnet.framework.aspnet.webservices
Conversation: Changing namespace of a Soap Header
Subject: Re: Changing namespace of a Soap Header

Christoph,

Thanks for the reply - I have good and bad news.

Turns out that your suggestion completely fixed the problem - IF - I have
the web service/proxy using document encoded SOAP. However, if I switch to
RPC encoded (and leave the XmlElement in place), then the SOAP header
switches to what you saw earlier. The namespace for the header is switched
to <ns of the web service>/encodedTypes.

I don't know if that is part of the spec or not - I have not really messed
with RPC encoding. However, due to a customer requirement I need to be
able
to support both document and RPC.

Thoughts?

Brian


You can define the namespace of the header by attaching an XmlElement
attribute to the WebService class' header field:

[WebService(Namespace="http://www.bracketangles.net/ns")]
public class Service1 : System.Web.Services.WebService
{
// ...


[XmlElement(Namespace="http://www.bracketangles.net/headers")]
public MyHeader timeHeader;

[WebMethod]
[SoapHeader("timeHeader",
Direction=SoapHeaderDirection.InOut)]
//...

HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko


-----Original Message-----
From: Brian Tyler [mailto:[email protected]]
Posted At: Tuesday, January 18, 2005 1:49 PM
Posted To: microsoft.public.dotnet.framework.aspnet.webservices
Conversation: Changing namespace of a Soap Header
Subject: Changing namespace of a Soap Header

I have defined a soap header via the .NET framework

public sealed class MySoapHeader : SoapHeader
{
}

I can successfully send this header either from the client proxy or
from
the
web service itself. However, it seems that the "type" of the header is
always put into the namespace of the proxy or server. For example,
under a
simple proxy, I get

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="http://tempuri.org"
xmlns:types="http://tempuri.org/encodedTypes"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<types:MySoapHeader id="h_id1"> ...

Note that it is put into the "types" ns, which is based on the ns of
the
proxy.

How do I have the SOAP header have its own namespace? Something I can
define
as part of the Soap header so it stays the same regardless of the
proxy or
web service it is used with?

Thanks in advance

Brian
 

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

Top