1

我试图理解 C# 的 dotMailer API。

我有一个类库,我打算在其中存储将使用引用 1.5 版 API 的 dotMailer API 的功能。我还从这个WSDL设置了一个服务参考

我正在浏览 C# 示例,但我已经被难住了!以下是直接从这里拉出来的

C#中的使用示例

/// <summary>
/// Adds a contact to an address book
/// </summary>
public void AddContactToAddressBook() 
{
    const string username = "apiuser-XXXXXXXXXXXX@apiconnector.com";
    const string password = "password";
    const int addressBookId = 1;  // ID of the target address book

    Console.WriteLine("AddContactToAddressBook");
    Console.WriteLine("-----------------------");

    // Get an instance to the web reference
    com.apiconnector.API api = new com.apiconnector.API();

    try
    {
        // we need a new contact
        com.apiconnector.APIContact contact = new com.apiconnector.APIContact();

        // populate the contact
        contact.AudienceType = com.apiconnector.ContactAudienceTypes.B2B;

        // populate the data fields
        contact.DataFields = new com.apiconnector.ContactDataFields();
        contact.DataFields.Keys = new string[3];
        contact.DataFields.Values = new object[3];

        contact.DataFields.Keys[0] = "FIRSTNAME";
        contact.DataFields.Values[0] = "John";
        contact.DataFields.Keys[1] = "LASTNAME";
        contact.DataFields.Values[1] = "Smith";
        contact.DataFields.Keys[2] = "POSTCODE";
        contact.DataFields.Values[2] = "IP4 1XU";


        // email address
        contact.Email = "joe.smith@example.com";

        contact.EmailType =  com.apiconnector.ContactEmailTypes.PlainText;
        contact.Notes = "This is a test only email";
        contact.OptInType = com.apiconnector.ContactOptInTypes.Single;

        // This method will create the contact required if it doesn't already exist within the dotMailer system,
        // so we don't have to call CreateContact as a prerequisite.
        // 
        // This method will also overwrite an existing contact, with the information provided here.
        //
        // This method will fail if you try to add a contact to the "Test" or "All Contacts" address books.
        //
        com.apiconnector.APIContact newContact = api.AddContactToAddressBook(username, password, contact, addressBookId);

        // Did we get something back from the API ?
        if (newContact != null)
        {
            Console.WriteLine("Contact added to address book {0} -> {1}", newContact.ID, addressBookId);
        }
    }
    catch (SoapException ex)  // catch any soap issues/errors from the web service
    {
        Console.WriteLine("Error -> {0}", ex.Message);                
    }

    Console.WriteLine();
}

我的问题是以下行无法解决。

com.apiconnector.API api = new com.apiconnector.API();

我已经在命名空间dotMailer.Sdk.com.apiconnector中查找API但它不存在,那么它在哪里?

我错过了什么吗?

4

1 回答 1

1

将 wsdl 添加为服务引用。在下面的示例中,我将其称为“ServiceReference1”(因为这是默认设置,而且我很懒惰)。然后,您使用对 APISoapClient(我称之为客户端)的引用,而不是您在声明时遇到问题的“api”。

一切都编译得很好,我不打算执行它,因为我不知道我的随机代码片段会对服务器造成什么恶作剧!应该指出你正确的方向吗?

using WindowsFormsApplication1.ServiceReference1;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        const string username = "apiuser-XXXXXXXXXXXX@apiconnector.com";
        const string password = "password";
        const int addressBookId = 1;  // ID of the target address book


        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            AddContactToAddressBook();
        }

        private void AddContactToAddressBook()
        {
            using (ServiceReference1.APISoapClient Client = new ServiceReference1.APISoapClient())
            {
                APIContact Contact = new APIContact();
                Contact.AudienceType = ContactAudienceTypes.B2B;

                APIContact NewContact = Client.AddContactToAddressBook(username, password, Contact, addressBookId); // etc. etc.



            }
        }
    }
}
于 2013-08-02T15:11:43.187 回答