Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / February 2006

Tip: Looking for answers? Try searching our database.

Overriding the soapheader Namespace

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael Peters - 01 Feb 2006 17:46 GMT
I wish to change/set the namespace for a header in my web service.  I have
found the following code and it does not appear to work and my assumption is
because I am using RPC encoding...

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

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

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

Is there something I should use instead of the XmlElement to override the
header's namespace?

TIA
Steven Cheng[MSFT] - 02 Feb 2006 08:39 GMT
Hi Michael,

Welcome to the MSDN newsgroup.

As for the ASP.NET webservice's SoapHeader element namespace problem, it is
the expected behavior because the SOAP Rpc encoded message format won't
generate the SOAP message according to the WSDL xml schema or the .NET
class's xml seriazliation format. RPC style SOAP message will generate xml
content for a certain object structure following the encoding rules

#5.1 Rules for Encoding Types in XML
http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383513

So in order to make our web service's request/response SOAP message (XML
content) conforms to our XML schema or .NET class's xml serialization
defination, we should use  Document/Literal message style instead of
RPC/encoded....

Thanks,

Steven Cheng
Microsoft Online Support

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Michael Peters - 02 Feb 2006 12:52 GMT
So to clarify...there is no way for me to override/set the namespace for the
timeHeader structure below.
[WebService(Namespace="http://www.mydomain.net/ns")]
public class Service1 : System.Web.Services.WebService
{
// ...

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

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

> Hi Michael,
>
[quoted text clipped - 23 lines]
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
Steven Cheng[MSFT] - 03 Feb 2006 01:42 GMT
Thanks for your respone Michael,

Yes, for RPC style message, the soap header's element namespace is an
autogenerated encoding namespace, which derived from the service's
namespace but do not utilize the XML Element's namespace...   So those XML
Serizliation attribute can not control that.

Regards,

Steven Cheng
Microsoft Online Support

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Michael Peters - 10 Feb 2006 18:14 GMT
OK...here's a WSDL for a test webservice.  It appears to be
Document/Literal.  I also have the following line of code and it does not
appear to modify the WSDL.  Can you tell me why?

[WebService(Namespace="http://Com.SouthernCompany.SecurityTest/webservices/")]
public class Service1 : System.Web.Services.WebService

{

[XmlElement(Namespace="https://ws.southernco.com/CoolSecurity")]

public Com.SouthernCompany.Cool.Security.ScCredentials
authenticationCredentials;

<?xml version="1.0" encoding="utf-8" ?>
- <wsdl:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="http://Com.SouthernCompany.SecurityTest/webservices/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
targetNamespace="http://Com.SouthernCompany.SecurityTest/webservices/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
+ <s:schema elementFormDefault="qualified"
targetNamespace="http://Com.SouthernCompany.SecurityTest/webservices/">
- <s:element name="HelloWorld">
 <s:complexType />
 </s:element>
- <s:element name="HelloWorldResponse">
- <s:complexType>
- <s:sequence>
 <s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult"
type="s:string" />
 </s:sequence>
 </s:complexType>
 </s:element>
 <s:element name="ScCredentials" type="tns:ScCredentials" />
- <s:complexType name="ScCredentials">
- <s:sequence>
 <s:element minOccurs="0" maxOccurs="1" name="DirectUserNameToken"
type="tns:ScUserNameToken" />
 <s:element minOccurs="0" maxOccurs="1" name="OriginatingUserNameToken"
type="tns:ScUserNameToken" />
 <s:element minOccurs="0" maxOccurs="1" name="Created" type="s:string" />
 </s:sequence>
 </s:complexType>
- <s:complexType name="ScUserNameToken">
- <s:sequence>
 <s:element minOccurs="0" maxOccurs="1" name="UserName" type="s:string" />
 <s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string" />
 <s:element minOccurs="0" maxOccurs="1" name="Type" type="s:string" />
 <s:element minOccurs="0" maxOccurs="1" name="Nonce" type="s:string" />
 <s:element minOccurs="0" maxOccurs="1" name="BinarySecurityToken"
type="tns:ScBinarySecurityToken" />
 </s:sequence>
 </s:complexType>
- <s:complexType name="ScBinarySecurityToken">
- <s:sequence>
 <s:element minOccurs="0" maxOccurs="1" name="ID" type="s:string" />
 <s:element minOccurs="0" maxOccurs="1" name="ValueType" type="s:string" />
 </s:sequence>
 </s:complexType>
 </s:schema>
 </wsdl:types>
- <wsdl:message name="HelloWorldSoapIn">
 <wsdl:part name="parameters" element="tns:HelloWorld" />
 </wsdl:message>
- <wsdl:message name="HelloWorldSoapOut">
 <wsdl:part name="parameters" element="tns:HelloWorldResponse" />
 </wsdl:message>
- <wsdl:message name="HelloWorldScCredentials">
 <wsdl:part name="ScCredentials" element="tns:ScCredentials" />
 </wsdl:message>
- <wsdl:portType name="Service1Soap">
- <wsdl:operation name="HelloWorld">
 <wsdl:input message="tns:HelloWorldSoapIn" />
 <wsdl:output message="tns:HelloWorldSoapOut" />
 </wsdl:operation>
 </wsdl:portType>
- <wsdl:binding name="Service1Soap" type="tns:Service1Soap">
 <soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document" />
- <wsdl:operation name="HelloWorld">
 <soap:operation
soapAction="http://Com.SouthernCompany.SecurityTest/webservices/HelloWorld"
style="document" />
- <wsdl:input>
 <soap:body use="literal" />
 <soap:header message="tns:HelloWorldScCredentials" part="ScCredentials"
use="literal" />
 </wsdl:input>
- <wsdl:output>
 <soap:body use="literal" />
 <soap:header message="tns:HelloWorldScCredentials" part="ScCredentials"
use="literal" />
 </wsdl:output>
 </wsdl:operation>
 </wsdl:binding>
- <wsdl:service name="Service1">
- <wsdl:port name="Service1Soap" binding="tns:Service1Soap">
 <soap:address
location="http://localhost/WebServiceSecurityTest2/Service1.asmx" />
 </wsdl:port>
 </wsdl:service>
 </wsdl:definitions>

> Thanks for your respone Michael,
>
[quoted text clipped - 11 lines]
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
Steven Cheng[MSFT] - 15 Feb 2006 09:33 GMT
Hi Michael,

Have you tried directly apply namespace on the custom SoapHeader class
itself. like:

[XmlRoot("MySoapHeader",Namespace="http://mytest.dotnet.org")]
public class MyHeader : SoapHeader
{
  ...................

It works on my side.

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Michael Peters - 10 Feb 2006 18:37 GMT
I simply wish to override the namespace for the ScCredentials structure

Thank you,
MP

> Thanks for your respone Michael,
>
[quoted text clipped - 11 lines]
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
Michael Peters - 10 Feb 2006 18:59 GMT
And just incase you need it....here's the declaration for the method using
the SoapHeader..
[WebMethod]

[System.Web.Services.Protocols.SoapHeader("authenticationCredentials",
Direction=System.Web.Services.Protocols.SoapHeaderDirection.InOut)]

public string HelloWorld( string test)

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.