升级后 kentico CMS 中的 Web 服务错误
本文关键字:Web 服务 错误 中的 CMS kentico | 更新日期: 2023-09-27 18:32:23
我使用 Kentico CMS 8.0 创建了一个 Web 服务,我已将实例升级到 8.2。当我尝试从我的 Web 服务调用方法时,屏幕截图中出现错误。
这是我的方法:
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public string ProcessOrderGeneralDonation(Dictionary<string, object> request)
{
Dictionary<string, object> response;
ProcessDonationOrder(request, out response);
return JSONResponse(true, "Data Populated", response);
}
private void ProcessDonationOrder(Dictionary<string, object> request, out Dictionary<string, object> response, bool isChampionOfCare = false)
{
var dictionary = new Dictionary<string, object> { };
#region Customer
var customer = GetNewCustomerInfo(request);
var customerType = ValidationHelper.GetInteger(request["customer_type"], 0);
if (customerType == 2) //company
{
customer.CustomerCompany = ValidationHelper.GetString(request["customer_organization"], String.Empty);
}
CustomerInfoProvider.SetCustomerInfo(customer);
var country = CountryInfoProvider.GetCountryInfo(ValidationHelper.GetString(request["customer_country"], String.Empty).Replace(" ", ""));
//var state = StateInfoProvider.GetStateInfo(ValidationHelper.GetString(request["customer_province"], String.Empty));
// Create new address object
var customerAddress = GetNewCustomerAddressInfo(request, customer);
if (country != null)
customerAddress.AddressCountryID = country.CountryID;
// Create the address
AddressInfoProvider.SetAddressInfo(customerAddress);
customerAddress.SetValue("AddressPhone", ValidationHelper.GetString(request["customer_phone"], String.Empty));
customerAddress.SetValue("AddressStateOthers", ValidationHelper.GetString(request["customer_province"], String.Empty));
customerAddress.Update();
// Create order addresses from customer address
OrderAddressInfo orderBillingAddress = OrderAddressInfoProvider.CreateOrderAddressInfo(customerAddress);
OrderAddressInfo orderShippingAddress = OrderAddressInfoProvider.CreateOrderAddressInfo(customerAddress);
// Set the order addresses
OrderAddressInfoProvider.SetAddressInfo(orderBillingAddress);
OrderAddressInfoProvider.SetAddressInfo(orderShippingAddress);
#endregion
var guid = ValidationHelper.GetGuid(request["guid"], Guid.Empty);
string message;
#region Shopping Cart
//Get Product
var product = GetProductSKUInfo(guid, out message);
if (product == null)
{
response = null;
return;
}
//Get Shopping Cart
var cart = GetShoppingCart();
// Add item to cart object
var param = new ShoppingCartItemParameters(product.SKUID, 1)
{
ProductOptions = new List<ShoppingCartItemParameters>
{
new ShoppingCartItemParameters(ValidationHelper.GetInteger(request["designation_id"], 0), 1),
new ShoppingCartItemParameters(ValidationHelper.GetInteger(request["donation_amount_id"], 0), 1)
}
};
if (isChampionOfCare)
{
//Get Champions Of Care Option Id
var options = OptionCategoryInfoProvider.GetProductOptionCategories(product.SKUID, true, OptionCategoryTypeEnum.Text);
var opt = options.Tables[0].AsEnumerable().SingleOrDefault(x => x["CategoryName"].ToString().ToLower() == "coc");
if (opt != null)
{
var categoryId = ValidationHelper.GetInteger(opt["CategoryID"], 0);
var skuOpt = GetSKUOptions(product.SKUID, categoryId) as DataTable;
if (skuOpt != null)
{
var cocId = ValidationHelper.GetInteger(skuOpt.Rows[0]["SKUID"], 0);
var cocParam = new ShoppingCartItemParameters(cocId, 1)
{
Text = ValidationHelper.GetString(request["coc_text"], string.Empty)
};
param.ProductOptions.Add(cocParam);
}
}
}
ShoppingCartItemInfo cartItem = cart.SetShoppingCartItem(param);
cartItem.CartItemCustomData["other_amount"] = ValidationHelper.GetDouble(request["donation_other_amount"], 0);
cart.ShoppingCartCustomData["donation_type"] = "GEN";
// Save item to database
ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(cartItem);
cart.ShoppingCartBillingAddress = orderBillingAddress;
cart.ShoppingCartShippingAddress = orderShippingAddress;
cart.Customer = customer;
cart.Update();
ShoppingCartInfoProvider.SetOrder(cart);
dictionary.Add("order_id", cart.OrderId);
UpdateDonor(request, cart.OrderId);
if (EnablePurchase)
{
Receipt responseReceipt;
request.Add("product_sku", product.SKUID);
Purchase(request, cart, customer, customerAddress, out responseReceipt);
var paymentSuccessed = !responseReceipt.GetMessage().Contains("DECLINED");
if (paymentSuccessed)
{
//HandleOrderNotification(cart);
SendInvoiceEmail(cart.OrderId);
}
dictionary.Add("moneris_message", responseReceipt.GetMessage());
}
#endregion
response = dictionary;
}
我相信
问题是JSONResponse()
不知道如何将Dictionary<string,object>
序列化为有效的 JSON 格式。
看看其中一些答案来帮助您解决这个问题。 他们中的大多数人建议使用像 JSON.NET 这样的JSON库:
https://stackoverflow.com/a/6620173/2344773
https://stackoverflow.com/a/5597628/2344773
我已经将
JSON.NET 添加到我的项目和 JSONResponse() 函数中
private string JSONResponse(bool success, string message, object data = null)
{
var dictionary = new Dictionary<string, object> { { "success", success }, { "message", message }, { "data", data } };
return JsonConvert.SerializeObject(dictionary, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
}