Thanks
Balaji
08-23-2014 04:39 AM
What is the raw response?
object reference not set to an instance is as generic as anything.
08-23-2014 06:11 AM
Can i use this method in windows service ?
public static bool CreateTransaction(long profile_id, long payment_profile_id)
{
bool out_bool = false;
createCustomerProfileTransactionRequest request = new createCustomerProfileTransactionRequest();
XmlAPIUtilities.PopulateMerchantAuthentication((ANetApiRequest)request);
profileTransactionType new_trans = new profileTransactionType();
profileTransAuthOnlyType new_item = new profileTransAuthOnlyType();
new_item.customerProfileId = profile_id.ToString();
new_item.customerPaymentProfileId = payment_profile_id.ToString();
new_item.amount = 1.00m;
orderExType order = new orderExType();
order.invoiceNumber = "inv" + (DateTime.Now.Ticks % int.MaxValue).ToString();
order.description = "Example item";
new_item.order = order;
new_trans.Item = new_item;
request.transaction = new_trans;
System.Xml.XmlDocument response_xml = null;
bool bResult = XmlAPIUtilities.PostRequest(request, out response_xml);
object response = null;
createCustomerProfileTransactionResponse api_response = null;
if (bResult) bResult = XmlAPIUtilities.ProcessXmlResponse(response_xml, out response);
if (!(response is createCustomerProfileTransactionResponse))
{
ANetApiResponse ErrorResponse = (ANetApiResponse)response;
Console.WriteLine(String.Format("Created Transaction\n code: {0}\n msg: {1}", ErrorResponse.messages.message[0].code, ErrorResponse.messages.message[0].text));
return out_bool;
}
if (bResult) api_response = (createCustomerProfileTransactionResponse)response;
if (api_response != null)
{
out_bool = true;
Console.WriteLine("Created Transaction " + api_response.directResponse);
Console.WriteLine(String.Format(" code: {0}\n msg: {1}", api_response.messages.message[0].code, api_response.messages.message[0].text));
}
return out_bool;
}
output: out_bool =false
ErrorResponse.messages.message[0].text
above line am getting object reference not set to an instance.
08-24-2014 09:45 PM - edited 08-24-2014 09:49 PM
you can't assume ErrorResponse.messages.message[0] object exist.
run a debug and see what response is
08-25-2014 04:17 AM