|
|
Documentation Wiki > Developer Documentation > Web Service Guide > Getting Started: Developers and the ExactTarget API > Connecting to the Web Service API using WCF
Connecting to the Web Service API using WCFFrom $1(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 WCFYou 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 FileFollow these steps to create a new VS2010 or VS2008 ASP.NET web application project:
How To Connect to the Web Service API using WCF and C# CodeFollow these steps to create a new VS2010 or VS2008 ASP.NET web application project:
// 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 SubscriberSoapClient 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 MessageSoapClient 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:
Tags: (Edit tags)
|
|
Powered by MindTouch 2010 |