.NET Framework Bookmark and Share   
 index > ASMX Web Services and XML Serialization > CryptographicException: Bad Length while sending SOAP request through WSE3.0
 

CryptographicException: Bad Length while sending SOAP request through WSE3.0

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.
Sandy Kumar 2008
Sandy, no problem: I was trying to make sure everyone knows. Occasionally, I run into people who think that WSE is the current method of doing web services.

John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects
John Saunders
John: Do you have any idea about this problem?
Sandy Kumar 2008
No, sorry, I don't know WSE. I plan to shut up now, and hope that someone who knows WSE will answer you.


John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects
John Saunders
finally the issue has been resolve.

the issue was with Ssl certificate.
Sandy Kumar 2008

You can use google to search for other answers

Custom Search

More Threads

• I want to access a webservice from Remote server(www.yahoo.com) to local machine( 122.165.12.204: 8080 ). I did that concept but its displaying following error. pls immediatly give me solution.
• Web Service Data error checked?
• HELP Please - ActiveX, C# file downloading
• Dataset serialization error
• Website to WebApplication : WebReferences
• Getting the following erron when i tried to implement WCF into my project
• Upload an image
• Need help with making a client with SOAP
• reg web service and soapexception
• Problem in Updating Resource CalendarException using PSI WebServices