EDN Admin
Well-known member
Hi,
I have to send a SOAP request to a java web service. The reuqest is built manually using XSLT. I am not involved in the building of the request. I need to sign this SOAP request with an X.509 certificate and send it to the web service.
I am not allowed to use WSE or WCF as there is a limitation of software installation on the client machines. I am using the following code snippet to sign the request but the web service rejects the request with an "Invalid Signature". Where am
I going wrong?
Any assitance is would be greatly appreciated.
Thanks a lot in advance
Venkataramana
<span style="font-size:x-small <font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small SignedXml<span style="font-size:x-small signedXml =
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small new<span style="font-size:x-small
<span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small SignedXml<font size="2 (_soapRequest);</font><span style="font-size:x-small <font size="2" style="font-size:x-small
signedXml.SignedInfo.CanonicalizationMethod =
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small SignedXml<font size="2 .XmlDsigExcC14NTransformUrl;</font><span style="font-size:x-small
signedXml.SigningKey = _certificate.PrivateKey;
<font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small KeyInfoX509Data<span style="font-size:x-small x509Data =
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small new<span style="font-size:x-small
<span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small KeyInfoX509Data<font size="2 ();</font><span style="font-size:x-small
x509Data.AddIssuerSerial(_certificate.IssuerName.Name, _certificate.GetSerialNumberString());
<font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlElement<span style="font-size:x-small securityTokenReference = _soapRequest.CreateElement(<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "SecurityTokenReference"<span style="font-size:x-small ,
<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"<font size="2 );</font><span style="font-size:x-small <font size="2" style="font-size:x-small
securityTokenReference.AppendChild(_soapRequest.ImportNode(x509Data.GetXml(),
</font><span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small true<font size="2 ));</font><span style="font-size:x-small
signedXml.KeyInfo.AddClause(x509Data);
<font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small Reference<span style="font-size:x-small r =
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small new<span style="font-size:x-small
<span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small Reference<span style="font-size:x-small (<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "#"<font size="2
+ reference);</font><span style="font-size:x-small <font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlDsigExcC14NTransform<span style="font-size:x-small env =
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small new<span style="font-size:x-small
<span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlDsigExcC14NTransform<font size="2 ();</font><span style="font-size:x-small
r.AddTransform(env);
signedXml.AddReference(r);
signedXml.ComputeSignature();
<font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlElement<span style="font-size:x-small securityElement = _soapRequest.CreateElement(<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "wsse:Security"<span style="font-size:x-small ,
<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"<font size="2 );</font><span style="font-size:x-small <font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlElement<span style="font-size:x-small signature = (<span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlElement<span style="font-size:x-small )_soapRequest.ImportNode(signedXml.GetXml(),
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small true<font size="2 );</font><span style="font-size:x-small <font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlNamespaceManager<span style="font-size:x-small mgr =
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small new<span style="font-size:x-small
<span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlNamespaceManager<font size="2 (_soapRequest.NameTable);</font><span style="font-size:x-small <font size="2" style="font-size:x-small
mgr.AddNamespace(
</font><span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "ds"<span style="font-size:x-small ,
<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "http://www.w3.org/2000/09/xmldsig#"<font size="2 );</font><span style="font-size:x-small <font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlElement<span style="font-size:x-small x = (<span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlElement<span style="font-size:x-small )signature.SelectSingleNode(<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "ds:KeyInfo"<font size="2 ,
mgr);</font><span style="font-size:x-small
x.ReplaceChild(securityTokenReference, x.FirstChild);
securityElement.AppendChild(signature);
<font size="2" style="font-size:x-small
x = (
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlElement<span style="font-size:x-small )signature.SelectSingleNode(<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "//ds:CanonicalizationMethod"<font size="2 ,
mgr);</font><span style="font-size:x-small <font size="2" style="font-size:x-small
x.Prefix =
</font><span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "ds"<font size="2 ;</font><span style="font-size:x-small <font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlAttribute<span style="font-size:x-small actor = _soapRequest.CreateAttribute(<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "soap:actor"<font size="2 ,
soapNamespace);</font><span style="font-size:x-small <font size="2" style="font-size:x-small
actor.Value =
</font><span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "http://www.ncr.com/aptra/operate-ej"<font size="2 ;</font><span style="font-size:x-small
securityElement.Attributes.Append(actor);
<font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlAttribute<span style="font-size:x-small mustUnderstand = _soapRequest.CreateAttribute(<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "soap:mustUnderstand"<font size="2 ,
soapNamespace);</font><span style="font-size:x-small <font size="2" style="font-size:x-small
mustUnderstand.Value =
</font><span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "1"<font size="2 ;</font><span style="font-size:x-small
securityElement.Attributes.Append(mustUnderstand);
<font size="2" style="font-size:x-small
mgr =
</font><span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small new<span style="font-size:x-small
<span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlNamespaceManager<font size="2 (_soapRequest.NameTable);</font><span style="font-size:x-small <font size="2" style="font-size:x-small
mgr.AddNamespace(
</font><span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "soap"<span style="font-size:x-small ,
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small base<font size="2 .soapNamespace);</font><span style="font-size:x-small <font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlNode<span style="font-size:x-small soapHeader = _soapRequest.SelectSingleNode(<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "//soap:Header"<font size="2 ,
mgr);</font><span style="font-size:x-small
soapHeader.AppendChild(securityElement);
View the full article
I have to send a SOAP request to a java web service. The reuqest is built manually using XSLT. I am not involved in the building of the request. I need to sign this SOAP request with an X.509 certificate and send it to the web service.
I am not allowed to use WSE or WCF as there is a limitation of software installation on the client machines. I am using the following code snippet to sign the request but the web service rejects the request with an "Invalid Signature". Where am
I going wrong?
Any assitance is would be greatly appreciated.
Thanks a lot in advance
Venkataramana
<span style="font-size:x-small <font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small SignedXml<span style="font-size:x-small signedXml =
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small new<span style="font-size:x-small
<span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small SignedXml<font size="2 (_soapRequest);</font><span style="font-size:x-small <font size="2" style="font-size:x-small
signedXml.SignedInfo.CanonicalizationMethod =
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small SignedXml<font size="2 .XmlDsigExcC14NTransformUrl;</font><span style="font-size:x-small
signedXml.SigningKey = _certificate.PrivateKey;
<font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small KeyInfoX509Data<span style="font-size:x-small x509Data =
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small new<span style="font-size:x-small
<span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small KeyInfoX509Data<font size="2 ();</font><span style="font-size:x-small
x509Data.AddIssuerSerial(_certificate.IssuerName.Name, _certificate.GetSerialNumberString());
<font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlElement<span style="font-size:x-small securityTokenReference = _soapRequest.CreateElement(<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "SecurityTokenReference"<span style="font-size:x-small ,
<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"<font size="2 );</font><span style="font-size:x-small <font size="2" style="font-size:x-small
securityTokenReference.AppendChild(_soapRequest.ImportNode(x509Data.GetXml(),
</font><span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small true<font size="2 ));</font><span style="font-size:x-small
signedXml.KeyInfo.AddClause(x509Data);
<font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small Reference<span style="font-size:x-small r =
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small new<span style="font-size:x-small
<span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small Reference<span style="font-size:x-small (<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "#"<font size="2
+ reference);</font><span style="font-size:x-small <font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlDsigExcC14NTransform<span style="font-size:x-small env =
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small new<span style="font-size:x-small
<span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlDsigExcC14NTransform<font size="2 ();</font><span style="font-size:x-small
r.AddTransform(env);
signedXml.AddReference(r);
signedXml.ComputeSignature();
<font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlElement<span style="font-size:x-small securityElement = _soapRequest.CreateElement(<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "wsse:Security"<span style="font-size:x-small ,
<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"<font size="2 );</font><span style="font-size:x-small <font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlElement<span style="font-size:x-small signature = (<span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlElement<span style="font-size:x-small )_soapRequest.ImportNode(signedXml.GetXml(),
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small true<font size="2 );</font><span style="font-size:x-small <font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlNamespaceManager<span style="font-size:x-small mgr =
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small new<span style="font-size:x-small
<span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlNamespaceManager<font size="2 (_soapRequest.NameTable);</font><span style="font-size:x-small <font size="2" style="font-size:x-small
mgr.AddNamespace(
</font><span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "ds"<span style="font-size:x-small ,
<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "http://www.w3.org/2000/09/xmldsig#"<font size="2 );</font><span style="font-size:x-small <font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlElement<span style="font-size:x-small x = (<span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlElement<span style="font-size:x-small )signature.SelectSingleNode(<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "ds:KeyInfo"<font size="2 ,
mgr);</font><span style="font-size:x-small
x.ReplaceChild(securityTokenReference, x.FirstChild);
securityElement.AppendChild(signature);
<font size="2" style="font-size:x-small
x = (
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlElement<span style="font-size:x-small )signature.SelectSingleNode(<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "//ds:CanonicalizationMethod"<font size="2 ,
mgr);</font><span style="font-size:x-small <font size="2" style="font-size:x-small
x.Prefix =
</font><span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "ds"<font size="2 ;</font><span style="font-size:x-small <font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlAttribute<span style="font-size:x-small actor = _soapRequest.CreateAttribute(<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "soap:actor"<font size="2 ,
soapNamespace);</font><span style="font-size:x-small <font size="2" style="font-size:x-small
actor.Value =
</font><span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "http://www.ncr.com/aptra/operate-ej"<font size="2 ;</font><span style="font-size:x-small
securityElement.Attributes.Append(actor);
<font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlAttribute<span style="font-size:x-small mustUnderstand = _soapRequest.CreateAttribute(<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "soap:mustUnderstand"<font size="2 ,
soapNamespace);</font><span style="font-size:x-small <font size="2" style="font-size:x-small
mustUnderstand.Value =
</font><span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "1"<font size="2 ;</font><span style="font-size:x-small
securityElement.Attributes.Append(mustUnderstand);
<font size="2" style="font-size:x-small
mgr =
</font><span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small new<span style="font-size:x-small
<span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlNamespaceManager<font size="2 (_soapRequest.NameTable);</font><span style="font-size:x-small <font size="2" style="font-size:x-small
mgr.AddNamespace(
</font><span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "soap"<span style="font-size:x-small ,
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small base<font size="2 .soapNamespace);</font><span style="font-size:x-small <font size="2" style="font-size:x-small
</font><span style="color:#008080; font-size:x-small <span style="color:#008080; font-size:x-small XmlNode<span style="font-size:x-small soapHeader = _soapRequest.SelectSingleNode(<span style="color:#800000; font-size:x-small <span style="color:#800000; font-size:x-small "//soap:Header"<font size="2 ,
mgr);</font><span style="font-size:x-small
soapHeader.AppendChild(securityElement);
View the full article