Detached signature for WebMethods using .Net framework

Hello experts

Hello
I wrote the below functions to generate a detached signature that will be decrypted using WebMethods:

WebMethods generates the following error when trying to decrypt the signature signed using this VB.NET function

Certificate Verification Failed. Invalid Serial Number

Here is the VB.NET code:


Function SignString(ByVal strTosign As String) As String
        Dim docStrToSign As New XmlDocument
        docStrToSign.LoadXml(strTosign)
        docStrToSign.PreserveWhitespace = False
        Dim stringToSign As String = docStrToSign.OuterXml
        Dim utf8encoder As UTF8Encoding = New UTF8Encoding()
        Dim inputInBytes() As Byte = utf8encoder.GetBytes(stringToSign)
        Dim sigBytes() As Byte = ComputeSignature(inputInBytes)
        Return Convert.ToBase64String(sigBytes)
    End Function
    Function ComputeSignature(ByVal inputInBytes() As Byte) As Byte()
        Dim x509Cert As New X509Certificate2(System.Configuration.ConfigurationManager.AppSettings.Item("PrivateKeyPath") _
                                             & System.Configuration.ConfigurationManager.AppSettings.Item("PrivateKeyFile"), _
                                             System.Configuration.ConfigurationManager.AppSettings.Item("PrivateKeyPassword"))
        Dim ci As New ContentInfo(New Oid("1.3.14.3.2.26"), inputInBytes)
        Dim signed As New SignedCms(ci, True)
        Dim cs As New CmsSigner(x509Cert)
        cs.IncludeOption = X509IncludeOption.WholeChain
        signed.ComputeSignature(cs)
        Return signed.Encode()
End Function

Is there any compatibility issue between WebMethods cryptography and .Net framework cryptography?
The above code demonstrates the procedure proposed by our partner for signing XML messages using .Net framework.