Reputation: 52952
I'm trying to generate the following XML:
<wsse:Security>
<wsse:BinarySecurityToken
ValueType="Bibble"
EncodingType="wsse:Base64Binary"
wsu:Id="SecurityToken ">
Fish
</wsse:BinarySecurityToken>
</wsse:Security>
The code I have is:
protected override void OnWriteStartHeader(XmlDictionaryWriter writer, MessageVersion messageVersion)
{
writer.WriteStartElement("wsse", "Security" ,Namespace);
writer.WriteXmlnsAttribute("wsse", Namespace);
}
protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
{
writer.WriteStartElement("wsse", "BinarySecurityToken", Namespace);
writer.WriteAttributeString("ValueType", "Bibble");
writer.WriteAttributeString("EncodingType", "wsse:Base64Binary");
writer.WriteEndElement();
}
Problem 1: I can't figure out how to put the value of Fish between the start and end tags.
Problem 2: I can't figure out how to get the wsu:Id element, as this code generates an exception: writer.WriteAttributeString("wsu:Id", "SecurityToken");
Any ideas?
Upvotes: 3
Views: 1718
Reputation: 5636
In OnWriteHeaderContents()
, before your call to writer.WriteEndElement();
, add this:
writer.WriteValue("Fish");
Per MSDN, WriteValue
will take a string and simply write it out. There are other overloads for many different CLR types and object
.
So, OnWriteHeaderContents()
would look like this:
protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
{
writer.WriteStartElement("wsse", "BinarySecurityToken", Namespace);
writer.WriteAttributeString("ValueType", "Bibble");
writer.WriteAttributeString("EncodingType", "wsse:Base64Binary");
writer.WriteValue("Fish");//write Fish
writer.WriteEndElement();
}
Upvotes: 2
Reputation: 2655
Problem 1:
I can't seem to find XmlDictionaryWriter, but I believe you need
writer.WriteValue("Fish");
Problem 2:
Utilize one of the other overloads:
writer.WriteAttributeString("wsu", "Id", wsu_namespace_string, "SecurityToken");
where wsu_namespace_string contains the namespace declaration for the WSU prefix
Upvotes: 2