I've found a number of articles on this subject - but I can't seem to find the right combination to make this work. And not knowing C# very well - if really at all - I'm stuck. Here's my code - I'm sure I need to make some changes. When I access this in VB 6 I'm getting type mismatch errors...
using System;
public interface iCRMiCBIZ
{
string CreateAccount(string AccountName,string AccountNumber,string AddressLine1,string WebSiteURL );
string CreateContact(string FirstName, string LastName,string Telephone2,string EmailAddress );
string CreateAccountContacts(string AccountName, string AccountNumber,string AddressLine1,string WebSiteURL,string FirstName, string LastName,string Telephone2,string EmailAddress);
}
public class CRM
{
public static void CreateAccount(string AccountName,string AccountNumber,string AddressLine1,string WebSiteURL)
{
// strServer should be set with the name of the platform Web server
string strServer = "CTRF03";
// strVirtualDirectory should be set with the name of the Microsoft CRM
// virtual directory on the platform Web server
string strVirtualDirectory = "mscrmservices";
string strDir = " + strServer + "/" + strVirtualDirectory + "/";
// BizUser proxy object
Microsoft.CRM.Proxy.BizUser oBizUser = new Microsoft.CRM.Proxy.BizUser ();
oBizUser.Credentials = System.Net.CredentialCache.DefaultCredentials;
oBizUser.Url = strDir + "BizUser.srf";
// Account proxy object
Microsoft.CRM.Proxy.CRMAccount oAccount = new Microsoft.CRM.Proxy.CRMAccount ();
oAccount.Credentials = System.Net.CredentialCache.DefaultCredentials;
oAccount.Url = strDir + "CRMAccount.srf";
string strErrorMsg;
try
{
Microsoft.CRM.Proxy.CUserAuth oUserAuth = oBizUser.WhoAmI();
string strAccount = "<account>";
strAccount += "<name>" + AccountName + "</name>";
strAccount += "<accountnumber>" + AccountNumber + "</accountnumber>";
strAccount += "<address1_line1>" + AddressLine1 + "</address1_line1>";
strAccount += "<ownerid type=\"";
strAccount += Microsoft.CRM.Flags.ObjectType.otSystemUser.ToString();
strAccount += "\">" + oUserAuth.UserId;
strAccount += "</ownerid>";
strAccount += "<websiteurl>" + WebSiteURL + "</websiteurl>";
strAccount += "</account>";
string strAccountId = oAccount.Create(oUserAuth, strAccount);
//return AccountName;
}
catch(System.Web.Services.Protocols.SoapException err)
{
// Process the platform error here
strErrorMsg = ("ErrorMessage: " + err.Message + " " + err.Detail.OuterXml + " Source: " + err.Source );
}
catch(Exception err)
{
// Process other errors here
strErrorMsg = ("ErrorMessage: " + err.Message + "Source: " + err.Source );
}
}
............
using System;
public interface iCRMiCBIZ
{
string CreateAccount(string AccountName,string AccountNumber,string AddressLine1,string WebSiteURL );
string CreateContact(string FirstName, string LastName,string Telephone2,string EmailAddress );
string CreateAccountContacts(string AccountName, string AccountNumber,string AddressLine1,string WebSiteURL,string FirstName, string LastName,string Telephone2,string EmailAddress);
}
public class CRM
{
public static void CreateAccount(string AccountName,string AccountNumber,string AddressLine1,string WebSiteURL)
{
// strServer should be set with the name of the platform Web server
string strServer = "CTRF03";
// strVirtualDirectory should be set with the name of the Microsoft CRM
// virtual directory on the platform Web server
string strVirtualDirectory = "mscrmservices";
string strDir = " + strServer + "/" + strVirtualDirectory + "/";
// BizUser proxy object
Microsoft.CRM.Proxy.BizUser oBizUser = new Microsoft.CRM.Proxy.BizUser ();
oBizUser.Credentials = System.Net.CredentialCache.DefaultCredentials;
oBizUser.Url = strDir + "BizUser.srf";
// Account proxy object
Microsoft.CRM.Proxy.CRMAccount oAccount = new Microsoft.CRM.Proxy.CRMAccount ();
oAccount.Credentials = System.Net.CredentialCache.DefaultCredentials;
oAccount.Url = strDir + "CRMAccount.srf";
string strErrorMsg;
try
{
Microsoft.CRM.Proxy.CUserAuth oUserAuth = oBizUser.WhoAmI();
string strAccount = "<account>";
strAccount += "<name>" + AccountName + "</name>";
strAccount += "<accountnumber>" + AccountNumber + "</accountnumber>";
strAccount += "<address1_line1>" + AddressLine1 + "</address1_line1>";
strAccount += "<ownerid type=\"";
strAccount += Microsoft.CRM.Flags.ObjectType.otSystemUser.ToString();
strAccount += "\">" + oUserAuth.UserId;
strAccount += "</ownerid>";
strAccount += "<websiteurl>" + WebSiteURL + "</websiteurl>";
strAccount += "</account>";
string strAccountId = oAccount.Create(oUserAuth, strAccount);
//return AccountName;
}
catch(System.Web.Services.Protocols.SoapException err)
{
// Process the platform error here
strErrorMsg = ("ErrorMessage: " + err.Message + " " + err.Detail.OuterXml + " Source: " + err.Source );
}
catch(Exception err)
{
// Process other errors here
strErrorMsg = ("ErrorMessage: " + err.Message + "Source: " + err.Source );
}
}
............