How to add prefix "wsse" in ROOT node of SOAP Message (VB.NET)
-
Wednesday, March 11, 2009 6:41 PM
I am trying to consume a web service in .NET provided by the vendor. When I have created proxy class, through the wsdl.exe/svcutil.exe, .NET Framework 1.1/2.0/2.5, system didn't generate any code for ws-security policy.
I tried posting message through the WSE 2.0 but not luck. Vendor system does not understand the requested posted via the WSE 2.0/3.0.
Finally, I have wrote a custom class in proxy code to extend the SOAPHeader class and send the custom header along with the SOAPBody... I am able to send the message but I need to put a prefix "wsse" in the root element "Security". I tried manually set the header like "wsse:Security" but due to serialization problem system encodes it to _X03A_ tag. I have searched all the place but havn't seen a single solution which says, how to add the prefix in the root element. One suggestion, I have seen in someother post is to apply XSLT... Unfortunately, that solution also didn't work for me....
Here is my code... Any suggestions will be greatly appreciated..
_____________________
'''<remarks/>
<System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.1432"), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlRoot("Security", [Namespace]:="http://schemas.xmlsoap.org/ws/2002/04/secext")> _
Partial Public Class Security
Inherits System.Web.Services.Protocols.SoapHeader
Implements System.Xml.Serialization.IXmlSerializablePrivate WssePassword As String
Private WsseUsername As StringPrivate Const strxmlns As String = ""
Private Const strsqlns As String = ""
Private Const strwssens As String = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
Private Const strwsse As String = "wsse"
Private Const strUsernameToken As String = "UsernameToken"
Private Const strUsername As String = "Username"
Private Const strPassword As String = "Password"
Private Const strType As String = "Type"
Private Const strPasswordText As String = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"'''<remarks/>
Public Sub Security()
Me.WssePassword = "*****"
Me.WsseUsername = "*****"
End Sub'''<remarks/>
Public Function GetSchema() As System.Xml.Schema.XmlSchema _
Implements System.Xml.Serialization.IXmlSerializable.GetSchema
Dim _xmlSchema As New System.Xml.Schema.XmlSchema
_xmlSchema.Id = "Security"
Return _xmlSchema
End Function'''<remarks/>
Public Sub ReadXml(ByVal reader As XmlReader) _
Implements System.Xml.Serialization.IXmlSerializable.ReadXml
'Somthing
End Sub'''<remarks/>
Public Sub WriteXml(ByVal writer As XmlWriter) _
Implements System.Xml.Serialization.IXmlSerializable.WriteXmlIf strxmlns <> "" Or strwsse <> "" Then
writer.WriteAttributeString(strxmlns, strwsse, "", strwssens)
End If
If strxmlns <> "" Then
writer.WriteAttributeString(strxmlns, strwssens)
End If
If (Me.MustUnderstand) Then
writer.WriteAttributeString("mustUnderstand", "http://schemas.xmlsoap.org/soap/envelope/", Me.EncodedMustUnderstand)
End If
If (Me.Actor <> "") Then
writer.WriteAttributeString("actor", "http://schemas.xmlsoap.org/soap/envelope/", Me.Actor)
End If
writer.WriteStartElement(strwsse, strUsernameToken, strwssens)
writer.WriteStartElement(strwsse, strUsername, strwssens)
If (Me.WsseUsername = "") Then
writer.WriteAttributeString("xsi", "", "http://www.w3.org/2001/XMLSchema-instance", "true")
Else
writer.WriteString(Me.WsseUsername)
writer.WriteEndElement()
End Ifwriter.WriteStartElement(strwsse, strPassword, strwssens)
If (Me.WssePassword = "") Then
writer.WriteAttributeString("xsi", "", "http://www.w3.org/2001/XMLSchema-instance", "true")
Else
writer.WriteString(Me.WssePassword)
End If
writer.WriteEndElement()
writer.WriteEndElement()
End Sub'''<remarks/>
Public Property Password() As String
Get
Return Me.WssePassword
End Get
Set(ByVal value As String)
Me.WssePassword = value
End Set
End Property'''<remarks/>
Public Property Username() As String
Get
Return Me.WsseUsername
End Get
Set(ByVal value As String)
Me.WsseUsername = value
End Set
End Property
End Class
_____________________XML Output file
_____________________
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><wsse_x003A_Security xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns="******http://xml.nccw.nl/xml/soap-auth/"><wsse:UsernameToken><wsse:Username>***</wsse:Username><wsse:Password>***</wsse:Password></wsse:UsernameToken></wsse_x003A_Security></soap:Header><soap:Body><Find__CompIntfc__STATE xmlns="USACAhttp://xmlns.oracle.com/Enterprise/Tools/schemas/M250334.V1"><COUNTRY>USA</COUNTRY><STATE>CA</STATE></Find__CompIntfc__STATE></soap:Body></soap:Envelope>
_____________________Please let me know if you want to see complete code. I will post the file also.
Thanks,
Manoj
Manoj Negi
All Replies
-
Wednesday, February 22, 2012 12:57 PM
Sir,
Kindly send the complete coding to sumiit.dash@gmail.com. If possible send the codes in VB.
Thanks in advance.
Sumiit Kumar Dash

