Good day guys,
I have a client that wants to integrate F&O with another C# system, the approach I have used is :
- to make a call to the service operation to create a Purchase Order header and return it to the external system (this part is working)
- the second call is send purchase order lines with the Purchase Order ID generated from the first call (this part is not working)
I'm facing an error which says
Response Description : {
"Message": "An exception occured when invoking the operation - ",
"ExceptionType": "ErrorException",
"ActivityId": "485a3d26-fb28-0003-6e44-5a4828fbd801"
}
Below is the c# code for the second call which is giving me the error above.
string purch_ID = label1.Text; //PurchOrderID generated from first call
string createPO_Lines = ClientConfiguration.Default.UriString + "api/services/CreatePurchOrderServiceGroup/CreatePurchaseOrderService/createPurchOrderLines";
var request = HttpWebRequest.Create(createPO_Lines);
request.Headers[OAuthHelper.OAuthHeader] = OAuthHelper.GetAuthenticationHeader(true);
request.Method = "POST";
request.ContentType = "application/json";
// Pass parameters in JsonSerialize Object start
var requestContract = new
{
purchID = purch_ID,
itemID = "50100",
qty = 1
// siteID = "MainOffice",
// locationID = "MainOffice",
// warehouseID = "MainOffice"
};
var requestContractString = JsonConvert.SerializeObject(requestContract);
using (var stream = request.GetRequestStream())
{
using (var writer = new StreamWriter(stream))
{
writer.Write(requestContractString);
}
} // Pass parameters in JsonSerialize Object end
try
{
var response = request.GetResponse() as HttpWebResponse; //here is where im getting the exception
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader streamReader = new StreamReader(responseStream))
{
string responseString = streamReader.ReadToEnd();
//Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
//Assert.IsFalse(string.IsNullOrEmpty(responseString));
label2.Text = responseString;
Console.WriteLine(responseString);
}
}
}
catch (WebException ex)
{
Console.WriteLine("Exception Message :" + ex.Message);
if (ex.Status == WebExceptionStatus.ProtocolError)
{
var response = ((HttpWebResponse)ex.Response);
Console.WriteLine("Status Code : {0}", ((HttpWebResponse)ex.Response).StatusCode);
Console.WriteLine("Status Description : {0}", ((HttpWebResponse)ex.Response).StatusDescription);
Console.WriteLine(" meth : {0}", ((HttpWebResponse)ex.Response).Method);
var stream = response.GetResponseStream();
var reader = new StreamReader(stream);
var text = reader.ReadToEnd();
Console.WriteLine("Response Description : {0}", text);
label2.Text = text;
}
}
}
The code for the xpp method that will create the Purchase Order lines is as follows.
public str createPurchOrderLines(
//str strDataAreaId,
str purchID,
str itemID,
real qty
// str siteID,
// str locationID,
// str warehouseID
)
{
PurchLine purchline;
PurchTable purchTable_;
AxPurchLine axPurchLine;
str strDataAreaId = "USSI";
str result = "---";
itemID = "50100";
/* siteID = "MainOffice";
locationID = "MainOffice";
warehouseID = "MainOffice"; */
CreatePurchOrderClass createPO_Class = new CreatePurchOrderClass();
changecompany(strDataAreaId)
{
purchLine.clear();
purchTable_ = PurchTable::find(purchID);
purchLine.initFromPurchTable(purchTable_);
axPurchLine = AxPurchLine::newPurchLine(purchLine);
axpurchLine.parmItemId(itemID);
axPurchLine.parmPurchQty(10);
axPurchLine.parmPurchPrice(100);
// purchLine.InventDimId = createPO_Class.createInventDim(strDataAreaId, itemID, locationID, warehouseID, siteID);
axPurchLine.doSave();
result = (strFmt("New Purchase Line added to Purchase Order '%1'.", purchId));
}
return result;
}
Can you guys help me to debug this.