2016-04-26 28 views
1

我有一個C#應用程序,其中我使用wsdl導入了API方法,如Softlayer準則中所述。 通過將Container_Product_Order_Virtual_Guest_Upgrade結構傳遞給Product_Order服務來編輯虛擬客戶端。Product_Order verifyOrder API在添加guest_disks時失敗

除了爲guest_disks添加項目價格ID時,所有情況都很好,在約6-7秒後發生以下異常: 「請求已中止:連接意外關閉。 這與verifyOrder和placeOrder方法都會發生。

我檢查了Virtual_Guest :: getUpgradeItemPrices以確保來賓磁盤值是有效的(即使爲虛擬機傳遞了無效的itempriceIds導致了特定的錯誤響應,而不是像上面描述的一般異常) 。

我無法在文檔中找到任何可以提示我爲什麼可以升級除guest_disks外的任何細節。

編輯: 的要求剝離代碼:

  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); 
+0

能否請您提供您的代碼? – Toxantron

回答

0

這裏,有一個例子來提升其工作原理見下圖。我看到在你的代碼中你添加了不需要的packageId,刪除並重試。

另外,當您正在創建Web引用時,請嘗試在WSDL網址(v3.1) (例如)中使用最新版本的api。 https://api.softlayer.com/soap/v3.1/SoftLayer_Hardware_Server?wsdl

//----------------------------------------------------------------------- 
// <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); 
      } 
     } 
    } 
} 

讓我知道,如果這有助於

問候

+0

刪除PackageId不起作用。除此之外,就我所知,您的示例和我的代碼之間沒有區別(只有缺少的itemprice類別代碼,在我的情況下,這可能是包含2個或更多具有相同itempriceId的塊設備的場景中的問題) 。我將嘗試明天重新導入SoftLayer API,以按照您的建議包含v.3.1。 – basarab