We are creating a .net web service client for java based web service.
We are using UsernameForCertificateAssertion turnkey assertion.
Here is the code for my .net client.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Web.Services3;
using Microsoft.Web.Services3.Addressing;
using Microsoft.Web.Services3.Messaging;
using Microsoft.Web.Services3.Security.X509;
using System.IO;
using System.Xml.Serialization;
using FintNamespace;
using Microsoft.Web.Services3.Design;
using Microsoft.Web.Services3.Security.Tokens;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Web.Services3.Security;
using Microsoft.Web.Services3.Security.Cryptography;
namespace PeopleSoftServiceClient
{
class PeopleSoftServiceClient
{
public const string DistinguishedName = "CN=AP Root CA, DC=corp, DC=asc, DC=com";
[MTAThread]
static void Main(string[] args)
{
Run();
}
private static void Run()
{
string path = System.Configuration.ConfigurationSettings.AppSettings["Path"];
string filePath = System.Configuration.ConfigurationSettings.AppSettings["XmlPath"];
string url = System.Configuration.ConfigurationSettings.AppSettings["URL"];
string certPath = System.Configuration.ConfigurationSettings.AppSettings["CertPath"];
try
{
PeopleSoftClient client = new PeopleSoftClient(new Uri(url));
Type type = typeof(FintNamespace.paymentOrigination);
XmlSerializer serializer = new XmlSerializer(type, "http://www.a.com/messages/fint");
UsernameForCertificateAssertion assertions = new UsernameForCertificateAssertion();
UsernameTokenProvider provider = new UsernameTokenProvider("Bob", "Bobby");
assertions.ServiceActor = "http://schemas.xmlsoap.org/soap/actor/next";
assertions.X509TokenProvider = new X509TokenProvider(StoreLocation.CurrentUser, StoreName.Root, DistinguishedName, X509FindType.FindByIssuerDistinguishedName);
assertions.UsernameTokenProvider = provider;
Policy policy = new Policy(new PolicyAssertion[] { assertions });
paymentOrigination origination = (paymentOrigination)serializer.Deserialize(new FileStream(filePath, FileMode.Open));
Console.WriteLine("Sending Request to AP...");
client.SetPolicy(policy);
client.SendPaymentOrigination(origination);
Console.WriteLine("Request Successfully sent...");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally { }
Console.ReadLine();
}
}
}
Code for PeopleSoftClient Class: -
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Web.Services3.Messaging;
using FintNamespace;
namespace PeopleSoftServiceClient
{
[SoapService("https://111.222.011.221:9442/PSIGW/PeopleSoftServiceListeningConnector")]
public class PeopleSoftClient : SoapClient
{
public PeopleSoftClient(Uri to) : base(to) { }
[SoapMethod("https://111.222.011.221:9442/PSIGW/PeopleSoftServiceListeningConnector?Operation=PaymentOrigination.v1&From=Z_CSS")]
public void SendPaymentOrigination(paymentOrigination paymentOrigination)
{
base.SendRequestResponse("PaymentOrigination.v1", paymentOrigination).GetBodyObject(typeof(paymentOrigination),
SoapServiceAttribute.TargetNamespace);
}
}
}
After executing the above console application, we get a CryptographicException: Bad Length.
System.Security.Cryptography.CryptographicException: Bad Length.
at System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr)
at System.Security.Cryptography.Utils._EncryptPKWin2KEnh(SafeKeyHandle hPubKey, Byte[] key, Boolean fOAEP, Int32& hr)
at System.Security.Cryptography.RSACryptoServiceProvider.Encrypt(Byte[] rgb,Boolean fOAEP)
at Microsoft.Web.Services3.Security.Cryptography.RSAOAEPKeyExchangeFormatter.EncryptKey(Byte[] plainKey)
at Microsoft.Web.Services3.Security.EncryptedKey.Encrypt()
at Microsoft.Web.Services3.Security.EncryptedKey.GetXml(XmlDocument document)
at Microsoft.Web.Services3.Security.Tokens.EncryptedKeyToken.GetXml(XmlDocument document)
at Microsoft.Web.Services3.Security.Security.SerializeXml(SoapEnvelope document)
at Microsoft.Web.Services3.Security.Security.Execute(SoapEnvelope envelope)
at Microsoft.Web.Services3.Security.SendSecurityFilter.ProcessMessage(SoapEnvelope envelope)
at Microsoft.Web.Services3.Pipeline.ProcessOutputMessage(SoapEnvelope envelope)
at Microsoft.Web.Services3.Messaging.SoapSender.FilterMessage(SoapEnvelope envelope)
at Microsoft.Web.Services3.Messaging.SoapSender.BeginSend(SoapEnvelope envelope, AsyncCallback callback, Object state)
at Microsoft.Web.Services3.Messaging.SoapClient.BeginSendOneWay(String methodname, SoapEnvelope envelope,
AsyncCallback callback, Object state)
at Microsoft.Web.Services3.Messaging.SoapClient.SoapClientAsyncResult..ctor(SoapClient client, String methodname,
SoapEnvelope envelope, AsyncCallback callback, Object state)
at Microsoft.Web.Services3.Messaging.SoapClient.SendRequestResponse(String methodname, SoapEnvelope envelope)
at Microsoft.Web.Services3.Messaging.SoapClient.SendRequestResponse(String methodname, Object obj)
at PeopleSoftServiceClient.PeopleSoftClient.SendPaymentOrigination(paymentOrigination paymentOrigination)
at PeopleSoftServiceClient.PeopleSoftServiceClient.Run()
Please let me know how to resolve this issue.
:JonSaunders: I know WSEis obsolete, but i have no choice.