Changing namespace of a Soap Header

Discussion in 'ASP .Net Web Services' started by Brian Tyler, Jan 18, 2005.

  1. Brian Tyler

    Brian Tyler Guest

    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
     
    Brian Tyler, Jan 18, 2005
    #1
    1. Advertising

  2. Brian Tyler

    Brian Tyler Guest

    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


    "Christoph Schittko [MVP]" wrote

    > 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:]
    > > 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

    >
    >
     
    Brian Tyler, Jan 19, 2005
    #2
    1. Advertising

  3. Brian Tyler

    Brian Tyler Guest

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

    Brian

    "Christoph Schittko [MVP]" <> wrote in message
    news:u5kZQ$...
    > 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:]
    > > 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
    > >
    > >
    > > "Christoph Schittko [MVP]" wrote
    > >
    > > > 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:]
    > > > > 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
    > > >
    > > >

    >
    >
     
    Brian Tyler, Jan 24, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mlt
    Replies:
    2
    Views:
    863
    Jean-Marc Bourguet
    Jan 31, 2009
  2. Andreas Remsperger

    Creating SOAP Header with namespace pefix

    Andreas Remsperger, Jan 30, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    193
    Andreas Remsperger
    Jan 30, 2004
  3. Magesh

    Changing the SOAP namespace

    Magesh, Oct 1, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    131
    Magesh
    Oct 1, 2004
  4. Peter van der veen

    How to add SOAP header to a SOAP message?

    Peter van der veen, Nov 8, 2006, in forum: ASP .Net Web Services
    Replies:
    6
    Views:
    602
    J. Dudgeon
    Nov 14, 2006
  5. David Clegg

    Changing the Namespace URI used for incoming SOAP requests

    David Clegg, May 5, 2008, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    224
    David Clegg
    May 5, 2008
Loading...

Share This Page