I have a C# COM visible DLL that works with web services. That COM visible DLL is being referenced and used in a VB6 application. The COM visible DLL has a function that pulls data from a web service call and gets the data in Json format, and then it also de-serializes the Json document to a class object, and returns the object id field (string type) from the function. The VB6 app calls that function and tries to get the id value. But it does not retrieve the value. The same COM Dll and same function is used in a .NET app. (C#), then the id field value can be retrieved.
How to get the correct value in VB 6 ? Highly Appreciate your response.
COM Dll function Code:
public string TestGETTransactionId(string transaction_id, ref string exceptionMessage)
{
exceptionMessage = "";
string sReturnString = " - 9999";
try
{
string sDomain = HostUrl;
string sNamespace = Namespace;
string sLocationId = LocationID;
string sDeveloperId = DeveloperID;
string sUserId = UserId;
string sUserAPIKey = UserApiId;
string sUserHashKey = UserHashKey;
string sEndPoint = TransactionsRetail;
//query to see if it is Okay...
sEndPoint = "transactions";
string sUrl = sDomain + @"/" + sNamespace + @"/" + sEndPoint + "?transaction_id=" + transaction_id;
var client = new RestClient(sUrl);
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("user-id", sUserId);
request.AddHeader("user-api-key", sUserAPIKey);
request.AddHeader("developer-id", sDeveloperId);
request.AddHeader("Content-Type", "application/json");
IRestResponse response = client.Execute(request);
TransactionRetail_Rootobject transactionRetail_Rootobject = SimpleJson.DeserializeObject<TransactionRetail_Rootobject>(response.Content);
if (transactionRetail_Rootobject.transactions != null)
{
sReturnString = transactionRetail_Rootobject.transactions[0].id.ToString();
}
}
catch (Exception ex)
{
exceptionMessage = ex.Message + "\n" + ex.InnerException;
}
return sReturnString;
}
VB6 Caller:
Dim sTransaction_api_id As String
Dim sExceptionMesg As String
Dim sReturnedId As String
'
sTransaction_api_id = "SAMINC_transID001" ' change this to try
sReturnedId = MyCOMDLL.MyComDllClass(sTransaction_api_id, sExceptionMesg)
MsgBox sReturnedId 'This always return the error code -9999 and I expect to get the true ID field value
MsgBox sExceptionMesg
C# Caller:
private void btnTestGetTransaction_Click(object sender, EventArgs e)
{
string sTransaction_id = "SAMINC_transID001";
string sExceptionMesg = "";
MyCOMDLL.MyComDllClass obj = new MyCOMDLL.MyComDllClass();
string sResult = obj.TestGETTransactionId(sTransaction_id, ref sExceptionMesg);
MessageBox.Show(sResult); // this returns the ID field value fine
textBox1.Text = sResult;
}
Thanks everyone.
What happened was I had to use a different way to make web services call. I use WinHttp reference in .NET to create routines for web services calls, instead of using RestClient. WinHttp provides more transparency to communicate with VB 6. The caller from VB 6 and C# do not need to change.