C# 添加来宾磁盘时,产品订单验证订单API失败
我有一个C#应用程序,其中我使用wsdl导入了API方法,如Softlayer指南中所述。 我正在编辑虚拟来宾,方法是将容器\u产品\u订单\u虚拟\u来宾\u升级结构传递到产品\u订单服务 除了为来宾_磁盘添加项目价格ID外,其他一切都很好,在这种情况下,大约6-7秒后会引发以下异常: “请求被中止:连接意外关闭。” verifyOrder和placeOrder方法都会出现这种情况 我检查了Virtual_Guest::getUpgradeItemPrices,以确保来宾磁盘值有效(即使为VM传递无效的ItemPriceId会导致特定的错误响应,而不是像上面所述的一般异常) 我在文档中找不到任何可以提示我为什么可以升级除guest_磁盘以外的任何东西的详细信息 编辑: 按要求删除代码:C# 添加来宾磁盘时,产品订单验证订单API失败,c#,api,ibm-cloud-infrastructure,C#,Api,Ibm Cloud Infrastructure,我有一个C#应用程序,其中我使用wsdl导入了API方法,如Softlayer指南中所述。 我正在编辑虚拟来宾,方法是将容器\u产品\u订单\u虚拟\u来宾\u升级结构传递到产品\u订单服务 除了为来宾_磁盘添加项目价格ID外,其他一切都很好,在这种情况下,大约6-7秒后会引发以下异常: “请求被中止:连接意外关闭。” verifyOrder和placeOrder方法都会出现这种情况 我检查了Virtual_Guest::getUpgradeItemPrices,以确保来宾磁盘值有效(即使为VM
SoftLayer_Virtual_Guest[] _VMtoEditList = new SoftLayer_Virtual_Guest[1] { -- Vm instance details are retrieved from SL according to the passed VM ID; };
List<SoftLayer_Product_Item_Price> _itemPriceList = new List<SoftLayer_Product_Item_Price>();
foreach (-- collection of properties to be upgraded )
{
SoftLayer_Product_Item_Category _category = new SoftLayer_Product_Item_Category();
_category.categoryCode = -- retrieved from the collection on which I iterate (eg "guest_disk0", "ram", etc.);
SoftLayer_Product_Item_Price _itemPrice = new SoftLayer_Product_Item_Price();
_itemPrice.id = -- the item priceID for the current item;
_itemPrice.idSpecified = true;
_itemPrice.categories = new SoftLayer_Product_Item_Category[1] { _category };
_itemPriceList.Add(_itemPrice);
}
SoftLayer_Product_Item_Price[] _itemPricesArray = _itemPriceList.ToArray();
SoftLayer_Container_Product_Order_Property _property1 = new SoftLayer_Container_Product_Order_Property();
_property1.name = "NOTE_GENERAL";
_property1.value = -- order's description;
SoftLayer_Container_Product_Order_Property _property2 = new SoftLayer_Container_Product_Order_Property();
_property2.name = "MAINTENANCE_WINDOW";
_property2.value = "now";
// Build SoftLayer_Container_Product_Order_Property
SoftLayer_Container_Product_Order_Property[] properties = new SoftLayer_Container_Product_Order_Property[2] { _property1, _property2 };
-- create container
SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade _upgradeContainer = new SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade();
_upgradeContainer.virtualGuests = _VMtoEditList;
_upgradeContainer.prices = _itemPricesArray;
_upgradeContainer.properties = properties;
_upgradeContainer.packageId = 46;
_upgradeContainer.packageIdSpecified = true;
SoftLayer_Product_OrderService service = new SoftLayer_Product_OrderService();
-- authentication structure is created here
SoftLayer_Container_Product_Order _verifiedOrder = service.verifyOrder(_upgradeContainer);
service.placeOrder(_verifiedOrder, false);
SoftLayer_Virtual_Guest[]\u VMtoEditList=新建SoftLayer_Virtual_Guest[1]{--根据传递的Vm ID从SL检索Vm实例详细信息;};
列表_itemPriceList=新列表();
foreach(--要升级的属性集合)
{
软件层\产品\项目\类别\类别=新软件层\产品\项目\类别();
_category.categoryCode=--从我迭代的集合中检索(例如“guest_disk0”、“ram”等);
软件层\产品\项目\价格\项目价格=新软件层\产品\项目\价格();
_itemPrice.id=--当前项目的项目priceID;
_itemPrice.idSpecified=true;
_itemPrice.categories=新软件层\产品\项目\类别[1]{{{U类别};
_itemPriceList.Add(_itemPrice);
}
SoftLayer_Product_Item_Price[]_itemPricesArray=_ItemPriceslist.ToArray();
SoftLayer_容器_产品_订单_属性_属性1=新的SoftLayer_容器_产品_订单_属性();
_property1.name=“注\概述”;
_property1.value=--订单描述;
SoftLayer_容器_产品_订单_属性_属性2=新的SoftLayer_容器_产品_订单_属性();
_property2.name=“维护窗口”;
_property2.value=“现在”;
//构建SoftLayer\u容器\u产品\u订单\u属性
SoftLayer_容器_产品_订单_属性[]属性=新SoftLayer_容器_产品_订单_属性[2]{u属性1,_属性2};
--创建容器
软件层\容器\产品\订单\虚拟\客户\升级\升级容器=新软件层\容器\产品\订单\虚拟\客户\升级();
_upgradeContainer.virtualGuests=\u VMtoEditList;
_upgradeContainer.prices=\u itemPricesArray;
_upgradeContainer.properties=属性;
_upgradeContainer.packageId=46;
_upgradeContainer.packageIdSpecified=true;
SoftLayer_Product_OrderService=新的SoftLayer_Product_OrderService();
--身份验证结构是在这里创建的
软件层\容器\产品\订单\验证订单=服务。验证订单(\升级容器);
服务.下单(_-verifiedOrder,false);
这里有一个升级的例子,可以看到下面的例子。我看到您的代码中添加了不需要的packageId,请删除并重试
此外,在创建web引用时,请尝试在WSDL url(v3.1)中使用最新版本的api
e、 g
//-----------------------------------------------------------------------
//
//软层技术公司。
//
//
// http://sldn.softlayer.com/article/License
//
//-----------------------------------------------------------------------
命名空间虚拟用户
{
使用制度;
使用System.Collections.Generic;
类PlaceOrderUpgrade
{
///
///为虚拟来宾订购升级
///此脚本为虚拟来宾命令升级,在这种情况下,我们将为虚拟来宾升级ram,
///它使用SoftLayer_容器_产品_订单_虚拟_来宾_升级容器和SoftLayer_产品_订单::placeOrder
///方法。
///有关详细信息,请查看以下链接:
///
///
/// http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
/// http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade/
/// http://sldn.softlayer.com/reference/services/SoftLayer_Product_Item_Price/
///
静态void Main(字符串[]参数)
{
//您可以使用SoftLayer用户名
字符串username=“设置我”;
//您的SoftLayer API密钥。
string apiKey=“设置我”;
//定义虚拟来宾id以进行升级
int virtualId=13115425;
//创建与SoftLayer\u Product\u Order API服务的连接,以及
//绑定我们的API用户名和密钥。
authenticate=new authenticate();
authenticate.username=用户名;
authenticate.apiKey=apiKey;
SoftLayer_Product_OrderService OrderService=新的SoftLayer_Product_OrderService();
orderService.authenticateValue=验证;
//使用您想要订购的价格的ID构建SoftLayer\u Product\u Item\u Price对象。
//您可以使用SoftLayer\u Product\u Package::getItemPrices方法检索它们
int[]价格={
1645
};
列表价格列表=新列表();
foreach(价格中的var价格)
{
索特拉
//-----------------------------------------------------------------------
// <copyright file="PlaceOrderUpgrade.cs" company="Softlayer">
// SoftLayer Technologies, Inc.
// </copyright>
// <license>
// http://sldn.softlayer.com/article/License
// </license>
//-----------------------------------------------------------------------
namespace VirtualGuests
{
using System;
using System.Collections.Generic;
class PlaceOrderUpgrade
{
/// <summary>
/// Order an upgrade for Virtual Guest
/// This script orders an upgrade for Virtual Guest, in this case we will upgrade the ram for a Virtual Guest,
/// It uses SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade container and SoftLayer_Product_Order::placeOrder
/// method for it.
/// For more information, review the following links:
/// </summary>
/// <manualPages>
/// http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
/// http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade/
/// http://sldn.softlayer.com/reference/services/SoftLayer_Product_Item_Price/
/// </manualPages>
static void Main(String [] args)
{
// You SoftLayer username
string username = "set me";
// Your SoftLayer API key.
string apiKey = "set me";
// Define the virtual guest id to place an upgrade
int virtualId = 13115425;
// Creating a connection to the SoftLayer_Product_Order API service and
// bind our API username and key to it.
authenticate authenticate = new authenticate();
authenticate.username = username;
authenticate.apiKey = apiKey;
SoftLayer_Product_OrderService orderService = new SoftLayer_Product_OrderService();
orderService.authenticateValue = authenticate;
// Build a SoftLayer_Product_Item_Price objects with the ids from prices that you want to order.
// You can retrieve them with SoftLayer_Product_Package::getItemPrices method
int[] prices = {
1645
};
List<SoftLayer_Product_Item_Price> pricesList = new List<SoftLayer_Product_Item_Price>();
foreach (var price in prices)
{
SoftLayer_Product_Item_Price newPrice = new SoftLayer_Product_Item_Price();
newPrice.id = price;
newPrice.idSpecified = true;
pricesList.Add(newPrice);
}
// Build SoftLayer_Container_Product_Order_Property object for the upgrade
SoftLayer_Container_Product_Order_Property property = new SoftLayer_Container_Product_Order_Property();
property.name = "MAINTENANCE_WINDOW";
property.value = "NOW";
List<SoftLayer_Container_Product_Order_Property> propertyList = new List<SoftLayer_Container_Product_Order_Property>();
propertyList.Add(property);
// Build SoftLayer_Virtual_Guest object with the id from vsi that you wish to place an upgrade
SoftLayer_Virtual_Guest virtualGuest = new SoftLayer_Virtual_Guest();
virtualGuest.id = virtualId;
virtualGuest.idSpecified = true;
List<SoftLayer_Virtual_Guest> virtualGuests = new List<SoftLayer_Virtual_Guest>();
virtualGuests.Add(virtualGuest);
// Build SoftLayer_Container_Product_Order object containing the information for the upgrade
//SoftLayer_Container_Product_Order orderTemplate = new SoftLayer_Container_Product_Order();
SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade orderTemplate = new SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade();
orderTemplate.containerIdentifier = "SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade";
orderTemplate.prices = pricesList.ToArray();
orderTemplate.properties = propertyList.ToArray();
orderTemplate.virtualGuests = virtualGuests.ToArray();
try
{
// We will check the template for errors, we will use the verifyOrder() method for this.
// Replace it with placeOrder() method when you are ready to order.
SoftLayer_Container_Product_Order verifiedOrder = orderService.verifyOrder(orderTemplate);
Console.WriteLine("Order Verified!");
}
catch (Exception e)
{
Console.WriteLine("Unable to place an upgrade for Virtual Guest: " + e.Message);
}
}
}
}