How can the pre-deifined schema namespaces in the soap msg be replaced?

I am testing the interoperability of ws-security between wse 2.0 and IBM websphere. And I found out they can not interoperate due to the inconsistency of the 'ws-security' schema refereneces between the sent msg by .net client and websphere web service.

Here is the soap msg sent by the .net client:

<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" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing"xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soap:Header>
<wsa:Action>
</wsa:Action>
<wsa:MessageID>uuid:3d6f545b-edfb-4454-9c0a-310adc6566c9</wsa:MessageID>
<wsa:ReplyTo>
<wsa:Address>http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</wsa:Address>
</wsa:ReplyTo>
<wsa:To>http://localhost:9080/TestSec/services/WorkOrderManager</wsa:To>
<wsse:Security>
<wsu:Timestamp wsu:Id="Timestamp-5077e331-0a80-4656-9c2b-627d91af82c8">
<wsu:Created>2005-08-08T07:09:27Z</wsu:Created>
<wsu:Expires>2005-08-08T07:10:27Z</wsu:Expires>
</wsu:Timestamp>
<xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<wsse:SecurityTokenReference>
<wsse:KeyIdentifier ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier" EncodingType="/7RXqo1u7iKZYkIIsIBXOTweBto=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">/7RXqo1u7iKZYkIIsIBXOTweBto=</wsse:KeyIdentifier>
</wsse:SecurityTokenReference>
</KeyInfo>
<xenc:CipherData>
<xenc:CipherValue>HTYvpTmS/LTl4u7hpskJZInjv1aqlrDuxT4+V6Vo8I0z7QE5fOOEfX9tMjyFFSNab3AMr4U9d8fhHsJQ9eTpXCPnPQKxHVMp1KOCBgLttV/T4UiB/Di5FJSJdkWN/hfZ9bFo0h1kmp8DDPpmgwqECnRopQe1f0U8hB7XdgRoZ6Y=</xenc:CipherValue>
</xenc:CipherData>
<xenc:ReferenceList>
<xenc:DataReference URI="#EncryptedContent-132c4dc3-f0fe-4dba-974f-1ccd0a893c43" />
</xenc:ReferenceList>
</xenc:EncryptedKey>
</wsse:Security>
</soap:Header>
<soap:Body>
<xenc:EncryptedData Id="EncryptedContent-132c4dc3-f0fe-4dba-974f-1ccd0a893c43" Type="http://www.w3.org/2001/04/xmlenc#Content" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc" />
<xenc:CipherData>
<xenc:CipherValue>5m9PMO8OLnQ/Vpqa0yliE/XQo6qkNUVXEI9DpcNqJHfj3/NAQX/YjKJkuWLGbv/hmuPJOHEw8xebvITlfDO7YkNUlPpzVfai4wnKVLGwQnOCqM6WjEgHJO6qd1AdV/hIiMtEqz4GX1uqFGRQ79pn1ZsLR0zj0sk6Fy3lBMbGxO3nkSWPvOhNwyLdcMx2JcYi9TLdGi8yFMuOj3Sd3y5k9wsTxs82Uxa51rns48a1ofu4+uZBqSiYlj0GSiKvXQBC7SMne3DK5EI2+0Sr5LLmuG9Cf4uV5q+FOW3fIvD1gGbP9owOasw8afZKVmIaQWLb9eNdr1CecuRt/mKO6UWlc+npaIUt0EsK/x0SlU0LRpzX1j784m1sDsB+ieYztjSBfTrfkhayirRFU5ddo/sebT2VdZ1kSsX1iS7Bkqc7CqUMc+DyDCW6dYS39QRpDY11acDhSQph3ooVdD1j+GMe+xyKX4t4thWglOpgfikb+OWx7wLDcEwCoDKnxmK4iDvc</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedData>
</soap:Body>
</soap:Envelope>

The lines in red show the schema reference for ws-security. However, the websphere is using a former schema, which is"http://schemas.xmlsoap.org/ws/2003/06/secext", to check the msg and decrypt on the service side. Unfortunately, I can not find a way to change the schema reference in webshpere. so I wonder if it is possible to replace the reference in .net wse to make it identical to the required schema reference?

[6160 byte] By [JustinTang] at [2007-12-16]
# 1
Hello Justin,

Unfortunately there is no easy way to do this. Basically this means that we built the WSE2.0SP3 release according to the WS-Security specs defined here http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd

They are making updates to all of the WS-* specifications frequently, so there will be times that some web service providers support the newest version while others support only older versions.

I had a customer run into the same issue with WS-Addressing last week. The only way around this is to either create a soap filter or soap extension that parses the soap headers, and manually changes the namespace to the updated namespace. I do not know if this will break any of the processing on the .NET client side because some of the functionality may have been removed or changed between the older version and the newer version.

Here is some code that I used for the WS-Addressing issue that may help you. The hardest part will be finding a way to modify the soap envelope using XML objects. I'm not very good at that so you may need to research if there is a better way to do that. First thing is make sure you compare using Microsoft.Web.Services2.Security.WSSecurity.NamespaceURI

Hope this helps
-Todd

public override void ProcessMessage(SoapEnvelope envelope)

{

if (envelope == null)

throw new ArgumentException("No envelope");

// Remove 'xmlns:wsa="http..."' from the main <soap:Envelope/> tag

// of the soap request, and then add it back with the updated URL

for (int i=envelope.Envelope.Attributes.Count-1; i>=0; i--)

{

if (envelope.Envelope.AttributesIdea.LocalName == "wsa")

{

envelope.Envelope.Attributes.RemoveAt(i);

envelope.Envelope.SetAttribute("wsa","http://schemas.xmlsoap.org/ws/2004/08/addressing");

}

}

// ===================================================

ArrayList addNodes = new ArrayList(); // WS-Addressing nodes we'll add back to envelope

ArrayList removeNodes = new ArrayList(); // WS-Addressing nodes we're removing and correcting

for (int loop=0;loop<envelope.Header.ChildNodes.Count; loop++)

{

if (envelope.Header.ChildNodes[loop].NamespaceURI == Microsoft.Web.Services2.Addressing.WSAddressing.NamespaceURI)

{

XmlElement node = envelope.CreateElement(envelope.Header.ChildNodes[loop].Prefix, envelope.Header.ChildNodes[loop].LocalName, "http://schemas.xmlsoap.org/ws/2004/08/addressing");

// Now we have to get child nodes and correct them too... GRRRRR

// Note: I only did this one level deep, so if you have something that looks like

// below then you'll need to nest this again, or do some recursion

// <wsa:ReplyTo

// <wsa:Address

// <wsa:something?

XmlNodeList nodeList = envelope.Header.ChildNodes[loop].ChildNodes;

for (int i=0; i<nodeList.Count; i++)

{

if (nodeListIdea is XmlElement && nodeListIdea.NamespaceURI == "http://schemas.xmlsoap.org/ws/2004/03/addressing")

{

XmlElement childnode = envelope.CreateElement(nodeListIdea.Prefix, nodeListIdea.LocalName, "http://schemas.xmlsoap.org/ws/2004/08/addressing");

childnode.InnerXml = nodeListIdea.InnerXml;

node.AppendChild(childnode);

}

else

{

node.AppendChild(nodeListIdea);

}

}

// Now we have the updated node built

// add it to nodes we want to add and

// add the current node we're looking at to the remove list

addNodes.Add(node);

removeNodes.Add(envelope.Header.ChildNodes[loop]);

}

}

// Remove all the nodes for WS-Addressing pointing to 2004/03

foreach ( XmlNode node in removeNodes )

{

envelope.Header.RemoveChild(node);

}

// Add all the nodes for WS-Addressing pointing to 2004/08

foreach ( XmlNode node in addNodes )

{

envelope.Header.AppendChild(node);

}

}

}

}

ToddFoust at 2007-9-9 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...

.NET Development

Site Classified