Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wrapper for C# - Use VB 6 - COM

Status
Not open for further replies.

tlatacki

Programmer
Nov 25, 2003
1
US
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 = &quot;<account>&quot;;
strAccount += &quot;<name>&quot; + AccountName + &quot;</name>&quot;;
strAccount += &quot;<accountnumber>&quot; + AccountNumber + &quot;</accountnumber>&quot;;
strAccount += &quot;<address1_line1>&quot; + AddressLine1 + &quot;</address1_line1>&quot;;
strAccount += &quot;<ownerid type=\&quot;&quot;;
strAccount += Microsoft.CRM.Flags.ObjectType.otSystemUser.ToString();
strAccount += &quot;\&quot;>&quot; + oUserAuth.UserId;
strAccount += &quot;</ownerid>&quot;;
strAccount += &quot;<websiteurl>&quot; + WebSiteURL + &quot;</websiteurl>&quot;;
strAccount += &quot;</account>&quot;;
string strAccountId = oAccount.Create(oUserAuth, strAccount);

//return AccountName;

}
catch(System.Web.Services.Protocols.SoapException err)
{
// Process the platform error here
strErrorMsg = (&quot;ErrorMessage: &quot; + err.Message + &quot; &quot; + err.Detail.OuterXml + &quot; Source: &quot; + err.Source );
}
catch(Exception err)
{
// Process other errors here
strErrorMsg = (&quot;ErrorMessage: &quot; + err.Message + &quot;Source: &quot; + err.Source );
}
}
............
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top