Migrate with C#

This section explains how to edit the files in your application to use P12 authentication. If you do not have the files that are mentioned in this section, you can find them in the most recent version of the C# SOAP toolkit in GitHub.
Follow these steps to upgrade your C# code:
  1. Add this service URL as a service reference to your project, and set
    N.NNN
    to the most recent server API version.
    https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_N.NNN.wsdl
    This step generates a Connected Services section in your project. It will also generate an
    app.config
    file for your project.
  2. Add these sections to the top of your
    app.config
    file:
    <configuration> <configSections> <section name="toolkitProperties" type="System.Configuration.NameValueSectionHandler"/> </configSections> <toolkitProperties> <add key="MERCHANT_ID" value="<your_merchant_id>"/> <add key="KEY_ALIAS" value="<your_certificate_key_alias>"/> <add key="KEY_FILE" value="<your_certificate_file>"/> <add key="KEY_PASS" value="<your_certificate_password>"/> <add key="KEY_DIRECTORY" value="<path/to/certificate/file>"/> </toolkitProperties> </configuration>
    The
    <configSections>
    element must be the first dependent element in the
    <configurations>
    element.
  3. In the generated
    app.config
    file, leave the
    <binding>
    section as it is.
    The
    <binding>
    section must look like this:
    <bindings> <basicHttpBinding> <binding name="ITransactionProcessor"> <security mode="Transport"/> </binding> </basicHttpBinding> </bindings>
  4. Add this dependency to the
    packages.config
    file:
    <packages> <package id="Portable.BouncyCastle" version="1.9.0" targetFramework="net472" /> </packages>
  5. Install this dependency by either running this command in your terminal or by another method:
    nuget install packages.config -OutputDirectory packages
  6. Add this package reference to your
    .csproj
    file:
    <Reference Include="BouncyCastle.Crypto, Version=1.9.0.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL"> <HintPath>packages\Portable.BouncyCastle.1.9.0\lib\net40\BouncyCastle.Crypto.dll</HintPath> </Reference>
    The steps for adding a new dependency can also be comleted through Visual Studio Package Manager.
  7. Add your P12 certificate to the Key directory.
    This
    KEY_DIRECTORY
    location must be accessible to your code. Ensure that your code has permission to read this location.
  8. Copy these files from the
    CSharpSoapToolkit/CSharpSoapToolkit
    folder to your project directory and import them to your project:
  9. Find these lines in your existing code:
    TransactionProcessorClient proc = new TransactionProcessorClient(); proc.ChannelFactory.Credentials.UserName.UserName = request.merchantID; proc.ChannelFactory.Credentials.UserName.Password = TRANSACTION_KEY; ReplyMessage reply = proc.runTransaction(request);
    Replace them with these lines:
    TransactionProcessorClient proc = new TransactionProcessorClient(); proc.Endpoint.EndpointBehaviors.Add(new InspectorBehavior()); ReplyMessage reply = proc.runTransaction(request);
  10. Find your installation of the .NET Framework.
    It is often in one of these locations:
    • C:\Windows\Microsoft.NET\Framework\v4.0.30319
      (32-bit)
    • C:\Windows\Microsoft.NET\Framework64\v4.0.30319
      (64-bit)
  11. Use the
    msBuild.exe
    file that is already in your system to compile your project.
    <path_to_framework>\msBuild.exe <name_of_project>.csproj
  12. Run the project executable:
    bin\<configuration>\<project_name>.exe
  13. To confirm that your configuration is updated successfully, you can use a Bearer token that verifies that your request is authenticated. To do so, add this command after line 59 in the
    InspectorBehavior.cs
    file from the
    CSharpSoapToolkit
    folder:
    Console.WriteLine(request.ToString());

What to Do Next

After completing the above migration steps, you must send a test authorization request using your P12 certificate to validate your migration. For more information, see Send a Test Request with P12 Authentication.