How to use the VerticalResponse API in C# & .NET

This sample application goes through the basic workflow of sending an email through the API using C# and .NET. It implements the following functionalities:

While the only necessary change is adding your account credentials to the code, we recommend also updating the contact information on lines 80-90 so that you actually receive the launched message.

Sample Code Details

The provided sample code was developed using Visual Studio Express 2010 on a Windows 7 computer. The sample was built using the Partner API WSDL, but it also works fine for those using the Enterprise API. If you are using the Enterprise API, keep in mind that there are some methods that aren't available without a Partner account (for example, sub-account creation and management). Check out the API documentation at http://developers.verticalresponse.com if there's any confusion; the Partner-only methods are flagged as such in the documentation.

Prerequisites & Notes

Running The Sample

  1. Open VRAPI_Sample_Application.sln in Visual Studio after extracting from VR_CSharp_Sample_Application.zip.
  2. Enter your account credentials on lines 31 and 32 of program.cs.
  3. Add your email address and name to the list you're creating in lines 80-90.
  4. Run the program! We usually use the debug feature within Visual Studio, so we've included a ReadLine at the bottom to keep the terminal window open.

Feel free to email us at api-support@verticalresponse.com if you have any questions or run into any difficulties.

For Partner API Users

Installing the Partner Client Certificates

If you are using the VerticalResponse Partner API (i.e. to access subaccounts and other features) you should have been given a certificate file that ends with a .p12 extension. Before you can perform any partner-specific functions, you will need to install that certificate on your machine.

Click on the .p12 file certificate file provided by Vertical Response.

Click "Next" on the first screen

The p12 file path should already be provided. If not, browse to it. Click Next.

Enter the certificate passphrase provided by Vertical Response.

Select "Place all certificates in the following store". Then click on Browse.

Check "Show Physical Stores" and select "Local Computer" under "Trusted Root Certification Authorities". Click "Okay".

Click "Finish" on the final screen.

Configuring Your App to Find the Partner Client Certificate

In order for the code to find your partner client certificates, you'll need to update the app.config file in the solution browser.

  1. In the VRAPIBinding binding entry under the system.servicemodel element, change the clientCredentialType parameter of the transport element from "None" to "Certificate"
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="VRAPIBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="Transport">
                        <transport clientCredentialType="Certificate" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
    
  2. In the client section, add a behaviorConfiguration parameter to the endpoint element and give it the value of clientEndpointCredential
    <client>
        <endpoint address="https://api.verticalresponse.com/1.0/VRAPI"
            binding="basicHttpBinding" bindingConfiguration="VRAPIBinding"
            contract="VRAPI.VRAPIPortType" name="VRAPIPort" behaviorConfiguration="clientEndpointCredential" />
    </client>
    
  3. We've included the necessary behaviors element (below) that will seek the certificate using its issuer name. If you have more than one partner client certificate stored in your environment, you will either need to remove any certificates you are not using or use a different identifier to select the correct certificate.
    	</client>
    	
    	<behaviors>
    	  <endpointBehaviors>
    	    <behavior name="clientEndpointCredential">
    	      <clientCredentials>
    	        <clientCertificate findValue="api-services@verticalresponse.com" storeName="Root" storeLocation="LocalMachine" x509FindType="FindByIssuerName"/>
    	      </clientCredentials>
    	    </behavior>
    	  </endpointBehaviors>
    	</behaviors>
    
    

If you have any issues, please contact api-support@verticalresponse.com and we'll be happy to troubleshoot with you.