Answered by:
WebService Client Adding Soap Header

Question
-
User1018509147 posted
I am new to .NET and webservices. I am trying to call a webservice written in Java. This is a two stage proces. The first is retrieving a <nonce> value. The second stage is to add the retrieved <nonce> value (which is series of numbers/chars. e.g 1234gh563432134e) to the Soap Header tag <Authentication>. The messgae should look as follows:
SOAP-ENV:Envelope
SOAP-ENV:encodingStyle=http://schemas.xmlsoap.org/soap/encoding/
xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/
xmlns:xsd=http://www.w3.org/2001/XMLSchema
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xmlns:SOAP-ENC=http://schemas.xmlsoap.org/soap/encoding/
xmlns:si="http://soapinterop.org/xsd"><SOAP-ENV:Header><authentication>
<nonce>13b9b5c6fffad00010de8d65b9647e0a</nonce>
<ident>test</ident>
<auth>c219245a06ba7b918c15c6b5b9e3a7b5</auth>
</authentication>
I am using a proxy class to invoke the required method, it is with this method; woningzoekendeupdate that i am trying to figure out how to add the authentication info to the SoapHeader:
[System.Web.Services.WebServiceBindingAttribute(Name = "bindingName", Namespace = "")]
public class SoapProxy : System.Web.Services.Protocols.SoapHttpClientProtocol
{
public SoapProxy()
{
//Webservice location
this.Url = "#";
}
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("woningzoekendeupdate", RequestNamespace = "#", Use = System.Web.Services.Description.SoapBindingUse.Default, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Default)]
[return: System.Xml.Serialization.XmlElement("contractaanbieding", Namespace = "#", DataType = "string")]
public string woningzoekendeupdate(object woningzoekendeupdate)
{
object[] results = this.Invoke("woningzoekendeupdate", new object[] { "dummy_parameter" });
return ((string)(results[0]));
}
}
Can anybody explain how to do this?
Friday, December 22, 2006 4:05 AM
Answers
-
User-1087479560 posted
Hi,
PLS refer to this article about how to use custom soaphead in .net:
http://www.codeproject.com/cs/webservices/authforwebservices.asp
Hope it helps.- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, December 25, 2006 12:33 AM -
User1018509147 posted
Thanks for your reply, I have been able to add a custom header using the following code:
[System.Web.Services.Protocols.
SoapDocumentMethod(Action = "woningzoekendeupdate", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[System.Web.Services.Protocols.SoapHeaderAttribute("AuthenticationHeader")]
[return: System.Xml.Serialization.XmlElement("contractaanbieding")]
public string woningzoekendeupdate([XmlElement(ElementName = "namesp1woningzoekendeupdate", IsNullable = true)] XmlDocument aanbieding)
{
object[] results = this.Invoke("woningzoekendeupdate", new object[] { aanbieding });
return ((string)(results[0]));
}
I have written a "get set" method in the same class as where the above method is written in to access "AuthenticationHeader":
public authentication AuthenticationHeader
{
get
{
return this._authenticationHeader;
}
set
{
this._authenticationHeader = value;
}
}
The authentication class has properties for the header which are set on initialisation of the class (so: new authentication). This means that before the header can actually be used the class needs to be initiated. The code isnt the most efficient one but for now it works I am planning to make the code cleaner and more logical.
Oh and before I forget this is the eseential part of the authentication class:
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = http://xml.nccw.nl/xml/soap-auth/)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://xml.nccw.nl/xml/soap-auth/", IsNullable = false)] public partial class authentication : System.Web.Services.Protocols.SoapHeader
{
//Put you public get set code here for you properties. String type can be used the essential header formatting for your SOAP header part is done by:
-- System.Web.Services.Protocols.SoapHeader
I am now trying to figure out who to add a prefix to my SOAP request. Currently I am sending a XML document enclosed in the element "woningzoekendupdate". I am trying to make that element into: namesp1:woningzoekendeupdate. If anyone has an idea on how to accomplish that.. I am all ears.
Cheers
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, December 26, 2006 12:49 PM
All replies
-
User-1087479560 posted
Hi,
PLS refer to this article about how to use custom soaphead in .net:
http://www.codeproject.com/cs/webservices/authforwebservices.asp
Hope it helps.- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, December 25, 2006 12:33 AM -
User1018509147 posted
Thanks for your reply, I have been able to add a custom header using the following code:
[System.Web.Services.Protocols.
SoapDocumentMethod(Action = "woningzoekendeupdate", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[System.Web.Services.Protocols.SoapHeaderAttribute("AuthenticationHeader")]
[return: System.Xml.Serialization.XmlElement("contractaanbieding")]
public string woningzoekendeupdate([XmlElement(ElementName = "namesp1woningzoekendeupdate", IsNullable = true)] XmlDocument aanbieding)
{
object[] results = this.Invoke("woningzoekendeupdate", new object[] { aanbieding });
return ((string)(results[0]));
}
I have written a "get set" method in the same class as where the above method is written in to access "AuthenticationHeader":
public authentication AuthenticationHeader
{
get
{
return this._authenticationHeader;
}
set
{
this._authenticationHeader = value;
}
}
The authentication class has properties for the header which are set on initialisation of the class (so: new authentication). This means that before the header can actually be used the class needs to be initiated. The code isnt the most efficient one but for now it works I am planning to make the code cleaner and more logical.
Oh and before I forget this is the eseential part of the authentication class:
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = http://xml.nccw.nl/xml/soap-auth/)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://xml.nccw.nl/xml/soap-auth/", IsNullable = false)] public partial class authentication : System.Web.Services.Protocols.SoapHeader
{
//Put you public get set code here for you properties. String type can be used the essential header formatting for your SOAP header part is done by:
-- System.Web.Services.Protocols.SoapHeader
I am now trying to figure out who to add a prefix to my SOAP request. Currently I am sending a XML document enclosed in the element "woningzoekendupdate". I am trying to make that element into: namesp1:woningzoekendeupdate. If anyone has an idea on how to accomplish that.. I am all ears.
Cheers
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, December 26, 2006 12:49 PM -
User1693166665 posted
Hi,
Did you ever figure out how to add the prefixes?
Thanks for your reply, I have been able to add a custom header using the following code:
[System.Web.Services.Protocols.SoapDocumentMethod(Action = "woningzoekendeupdate", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[System.Web.Services.Protocols.SoapHeaderAttribute("AuthenticationHeader")]
[return: System.Xml.Serialization.XmlElement("contractaanbieding")]
public string woningzoekendeupdate([XmlElement(ElementName = "namesp1woningzoekendeupdate", IsNullable = true)] XmlDocument aanbieding)
{
object[] results = this.Invoke("woningzoekendeupdate", new object[] { aanbieding });
return ((string)(results[0]));
}
I have written a "get set" method in the same class as where the above method is written in to access "AuthenticationHeader":
public authentication AuthenticationHeader
{
get
{
return this._authenticationHeader;
}
set
{
this._authenticationHeader = value;
}
}
The authentication class has properties for the header which are set on initialisation of the class (so: new authentication). This means that before the header can actually be used the class needs to be initiated. The code isnt the most efficient one but for now it works I am planning to make the code cleaner and more logical.
Oh and before I forget this is the eseential part of the authentication class:
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = http://xml.nccw.nl/xml/soap-auth/)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://xml.nccw.nl/xml/soap-auth/", IsNullable = false)]public partial class authentication : System.Web.Services.Protocols.SoapHeader
{
//Put you public get set code here for you properties. String type can be used the essential header formatting for your SOAP header part is done by:
-- System.Web.Services.Protocols.SoapHeader
I am now trying to figure out who to add a prefix to my SOAP request. Currently I am sending a XML document enclosed in the element "woningzoekendupdate". I am trying to make that element into: namesp1:woningzoekendeupdate. If anyone has an idea on how to accomplish that.. I am all ears.
Cheers
Tuesday, January 16, 2007 8:57 PM -
User-1970872809 posted
Hi,
Did you ever solve the problem with the namespace prefixes? I'm having the exact same problem right now.
Regards, ThaYoung1!
Thursday, April 17, 2008 4:01 AM -
User-1970872809 posted
Just solved the problem with the prefixes. More information: http://forums.asp.net/t/1249049.aspxMonday, April 21, 2008 8:22 AM -
User83269026 posted
I have managed to add authentication header check for more info http://www.my-php-scripts.net/index.php/dot-net-web-service-request-authentication-in-php-soap-server-advanced-php.htmlThursday, June 2, 2011 12:16 PM -
User2031037972 posted
Hi sithicus i want to create a nonce with 32 characters can you tell me the process for it ..Thanks in Advance
Friday, April 12, 2013 12:21 AM