Hi,
I tried to add a custom Header to a client message:
Dim newMessage As Message = buffer.CreateMessage()
newMessage.Headers.RemoveAt(0)
Dim memStream As New MemoryStream()
Dim xdw As XmlDictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(memStream)
xdw.WriteStartElement("wsse", "Security", http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd)
xdw.WriteStartElement("wsc", "SecurityContextToken", http://schemas.xmlsoap.org/ws/2005/02/sc)
xdw.WriteStartElement("wsc", "Identifier", http://schemas.xmlsoap.org/ws/2005/02/sc)
xdw.WriteString("Mytext Entry")
xdw.WriteEndElement()
xdw.WriteEndElement()
xdw.WriteEndElement()
xdw.Flush()
Dim MyHeader As MessageHeader
MyHeader.WriteHeader(xdw, request.Version)
newMessage.Headers.Add(MyHeader)
request = newMessage
I got the Methode from a Microsoft page:
http://msdn.microsoft.com/en-us/library/ms195423(v=VS.90).aspx
But it is not working, it throws an exception: Object reference not set to an instance of an object.
at line: MyHeader.WriteHeader(xdw, request.Version)
When I used the MessageHeader.CreateHeader("Name","","")
For both versions I am happy to get an answer for solving that problem
Lothar
I could not include Prefix for the Namespace
Loading
infoPosted Mar 21, 2011, 6:15 AM
when I derive from class MessageHeader, I get this:
Public
Class MyHeaderclassInherits System.ServiceModel.Channels.MessageHeader
Public Sub New(ByVal messageVersion As System.ServiceModel.Channels.MessageVersion)
Mybase.New()
End Sub Public Overrides ReadOnly Property Name As String
Get
End Get
End Property
Public Overrides ReadOnly Property [Namespace] As String
Get
End Get
End Property
Protected Overrides Sub OnWriteHeaderContents(ByVal writer As System.Xml.XmlDictionaryWriter, ByVal messageVersion As System.ServiceModel.Channels.MessageVersion)End Sub
End ClassI have to fill the readOnly Properties and so it will overwrite everything I put in my HeaderClass in the Code BeforeSendRequest.
If you have any idea, i would be happy
Regards
Lothar
Suthish NairPosted Mar 21, 2011, 5:54 AM
infoPosted Mar 21, 2011, 4:58 AM
what information do you want? Hole page?
I will get the Error on line: MyHeader.WriteHeader(xdw, request.Version)
The other version of creating a header is when you use
Dim MyHeader As MessageHeader
MyHeader = MessageHeader.CreateHeader("MyNewHeader",
infoPosted Mar 21, 2011, 4:57 AM
you did nothing except bitching around. So, please stop answering my question, if you don't understand. I never asked for examble code, I asked if somebody could explain why Microsoft is displaing a example an the Web which doesn't work.
And by the way, to derive from that clas does not work. Try it and learn!
I am a member in this forum since 2003 and I have enough experience in .Net.
Kind Regards
Lothar
Sam HobbsPosted Mar 18, 2011, 12:22 AM
The MessageHeader Class for C# is an abstract class and for VB it is "MustInherit". So what "info" needs to do is to create a class derived from MessageHeader, correct? I assume that there are articles explaining that, but "info" wants to use the sample code without learning how to use it. Even if someone was to provide more sample code for "info", "info" will need more and more and more until people stop helping "info" or "info" learns the language and reads the material.
Suthish NairPosted Mar 18, 2011, 12:21 AM
infoPosted Mar 17, 2011, 2:43 PM
Suthish NairPosted Mar 17, 2011, 1:27 PM
Dim MyHeader As New MessageHeader