Connecting to the Web Service API using WCF

From $1

    Doc-Wiki-BannerHK.png

    (Click the banner to go to the related Docs.Code.ExactTarget.com page.)

     

    This document contains conceptual and procedural information on connecting your development environment or other systems to the ExactTarget web service API using the WCF standards. 

    This information contains instructions for connecting using Visual Studio 2008 and Visual Studio Express 2008. For Visual Studio 2005 and Visual Studio Express 2005, use the instructions for connecting via WCE 3.0.

    Why Connect to the Web Service API using WCF

    You can use the connection to the web service API to test your calls and perform various tasks, such as sending email and retrieving tracking information.

    How To Connect to the Web Service API using WCF and the Web.config File

    Follow these steps to create a new VS2010 or VS2008 ASP.NET web application project:

    1. Create a new project using the ASP.NET Web Application template.
    2. Click OK.

      NewProject.png

    3. In your new project, add a service reference by right-clicking the References entry and selecting Add Service Reference.

      ServiceReference.png

      NOTE: If you work within Visual Studio 2010 and don't see the Add Service Reference option, change the target framework of your project from .NET Framework 4 Client Profile to .NET Framework 4.
    4. In the Add Service Reference window, enter the URL https://webservice.exacttarget.com/etframework.wsdl or https://webservice.s4.exacttarget.co...framework.wsdl (depending on what instance your account uses) in the Address field and enter your chosen value for the namespace. You can make the latter value whatever you want, but you must use that value consistently in your code.

      AddServiceReference.png

    5. Click OK.
    6. In the web.config file, create a "customBinding" node within the bindings section.
    7. Modify the "endpoint" node within the client section changing the binding attribute from "basicHttpBinding" to "customBinding".  If you used a Namespace value other than "ExactTargetClient", you will need to modify the "contract" attribute by replacing "ExactTargetClient" with the Namespace value you used.
      <bindings> 
          <customBinding>
              <binding name="SoapBinding" closeTimeout="00:30:00" openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00">
                  <security authenticationMode="UserNameOverTransport">
                      <secureConversationBootstrap />
                  </security>
                  <textMessageEncoding messageVersion="Soap11WSAddressingAugust2004" />
                  <httpsTransport maxReceivedMessageSize="655360000" />
              </binding>
          </customBinding>
      </bindings>
      <client>
          <endpoint address="https://webservice.exacttarget.com/Service.asmx" binding="customBinding" bindingConfiguration="SoapBinding" contract="ExactTargetClient.Soap" name="Soap" />
      </client>
    8. Save the file.

    How To Connect to the Web Service API using WCF and C# Code

    Follow these steps to create a new VS2010 or VS2008 ASP.NET web application project:

    1. Create a new project using the ASP.NET Web Application template.
    2. Click OK.

      NewProject.png

    3. In your new project, add a service reference by right-clicking the References entry and selecting Add Service Reference.

      ServiceReference.png

      NOTE: If you work within Visual Studio 2010 and don't see the Add Service Reference option, change the target framework of your project from .NET Framework 4 Client Profile to .NET Framework 4.
    4. In the Add Service Reference window, enter the URL https://webservice.exacttarget.com/etframework.wsdl or https://webservice.s4.exacttarget.co...framework.wsdl (depending on what instance your account uses) in the Address field and enter your chosen value for the namespace. You can make the latter value whatever you want, but you must use that value consistently in your code.

      AddServiceReference.png

    5. Click OK.
    6. Use the sample code to create the binding in your calls.
    // Create the binding
    BasicHttpBinding binding = new BasicHttpBinding();
    binding.Name = "UserNameSoapBinding";
    binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
    binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
    binding.ReceiveTimeout = new TimeSpan(0, 5, 0);
    binding.OpenTimeout = new TimeSpan(0, 5, 0);
    binding.CloseTimeout = new TimeSpan(0, 5, 0);
    binding.SendTimeout = new TimeSpan(0, 5, 0);
    
    // Set the transport security to UsernameOverTransport for Plaintext usernames
    EndpointAddress endpoint = new EndpointAddress("https://webservice.exacttarget.com/Service.asmx");
    
    // Create the SOAP Client (and pass in the endpoint and the binding)
    SoapClient etFramework = new SoapClient(binding, endpoint);
    
    // Set the username and password
    etFramework.ClientCredentials.UserName.UserName = "username";
    etFramework.ClientCredentials.UserName.Password = "password";
    Sample Code

    The sample code below demonstrates how to connect and interact with the web service API.

    Create a New Subscriber

    SoapClient framework = new SoapClient();
    framework.ClientCredentials.UserName.UserName = "XXXX";
    framework.ClientCredentials.UserName.Password = "XXXX";
    
    Subscriber sub = new Subscriber();
    sub.EmailAddress = "help@example.com";
    //Insert the following line if SubscriberKey functionality is enabled for your account.//
    sub.SubscriberKey = 'help@example.com';
    
    String requestID;
    String status;
    CreateResult[] cresults = framework.Create(new CreateOptions(), new APIObject[] { sub }, out requestID, out status);
    
    foreach (CreateResult result in cresults)
    {     Console.WriteLine(result.StatusMessage);
    }
    
    Console.WriteLine(requestID + ": " + status);

    Create a New Email Message

    SoapClient framework = new SoapClient();
    framework.ClientCredentials.UserName.UserName = userid;
    framework.ClientCredentials.UserName.Password = password;
    
    Email email = new Email();
    email.Name = "Mark-CC";
    email.Subject = "Mark-CC Subject Line";
    // more code...
    
    string requestID = string.Empty;
    string status = string.Empty;
    CreateResult[] results = framework.Create(new CreateOptions(), new APIObject[] { email }, out requestID, out status);

    You can also download the sample code attached at the bottom of the page to run a simple retrieve call that demonstrates you have correctly connected to the web service API using the WCF security specification.


    This page was last updated by Ryan Williams on Fri, 06 Jan 2012 21:27:26 GMT.

    If you require assistance with the ExactTarget application, please contact Global Support. If you wish to send Ryan direct feedback, fill out the form below:

     


    Was This Page Helpful?
    Suggestions or Comments:
    Name (optional):
    Email Address (optional):
    Enter 24205 backwards:
       
    Tags: (Edit tags)
    • No tags
    Comments (0)
    You must login to post a comment.

     
    Powered by MindTouch 2010
    Admin