Windows Azure REST API更新角色不起作用

时间:2013-10-03 18:13:10

标签: rest azure

我正在做一些关于azure概念工作的证明,尝试使用Get Role URL获取角色:

https://management.core.windows.net/<subscription-id>/services/hostedservices/<cloudservice-name>/deployments/<deployment-name>/roles/<role-name>

然后使用更新角色URL更新角色:

https://management.core.windows.net/<subscription-id>/services/hostedservices/<cloudservice-name>/deployments/<deployment-name>/roleinstances/<role-name>

这两个网址都是直接来自msdn网页。 GET请求有效,我得到的XML与我在管理控制台中看到的相匹配。 然后,当我向xml添加一个元素并将其与更新URL上的PUT一起发回时,我收到200响应,但我从未在管理控制台中看到更改。当我发送乱码时,我也没有看到任何错误消息。我是从C#连接的,同事建议我可以得到这个回复:

var response = (HttpWebResponse)request.GetResponse();
Console.WriteLine(response.ToString());

但是这给我带来了404错误。

是否有额外的步骤来提交更新?我怎样才能看到msdn提到的响应?

2 个答案:

答案 0 :(得分:0)

2条建议:

  1. 当我正在快速完成SMAPI工作时,我使用AzureTools(http://blogs.msdn.com/b/kwill/archive/2013/08/26/azuretools-the-diagnostic-utility-used-by-the-windows-azure-developer-support-team.aspx)。具体来说,请查看“服务管理REST API”下的“其他工具”部分。这将向您显示完整的回复。

  2. 回答有关如何获取响应的问题(txtSMAPIResponse是AzureTools提供响应信息的地方):

            System.IO.Stream receiveStream;
        System.IO.StreamReader readStream;
        Encoding encode;
    
        HttpWebResponse response = null;
        try
        {
            response = (HttpWebResponse)request.GetResponse();
        }
        catch (WebException ex)
        {
            txtSMAPIRequest.Text = request.Headers.ToString();
            txtSMAPIResponse.Text = ex.Message + Environment.NewLine + Environment.NewLine + ex.Response.Headers.ToString();
            try
            {
                receiveStream = ex.Response.GetResponseStream();
                encode = System.Text.Encoding.GetEncoding("utf-8");
                // Pipes the stream to a higher level stream reader with the required encoding format. 
                readStream = new System.IO.StreamReader(receiveStream, encode);
                txtSMAPIResponse.Text += readStream.ReadToEnd();
    
                // Releases the resources of the response.
                response.Close();
                // Releases the resources of the Stream.
                readStream.Close();
            }
            catch
            {
            }
            return;
        }
    
        txtSMAPIRequest.Text = request.Method + " " + request.RequestUri + " " + request.ProtocolVersion + Environment.NewLine + Environment.NewLine;
        txtSMAPIRequest.Text += request.Headers.ToString();
        txtSMAPIResponse.Text = (int)response.StatusCode + " - " + response.StatusDescription + Environment.NewLine + Environment.NewLine;
        txtSMAPIResponse.Text += response.Headers + Environment.NewLine + Environment.NewLine;
    
        receiveStream = response.GetResponseStream();
        encode = System.Text.Encoding.GetEncoding("utf-8");
        // Pipes the stream to a higher level stream reader with the required encoding format. 
        readStream = new System.IO.StreamReader(receiveStream, encode);
        txtSMAPIResponse.Text += readStream.ReadToEnd();
    
        // Releases the resources of the response.
        response.Close();
        // Releases the resources of the Stream.
        readStream.Close();
    }
    

答案 1 :(得分:0)

我遇到了同样的问题。在我的情况下,EndPointACL没有得到更新。非常痛苦的事情是每次更新,我们都要发送整个ConfigurationSet;无法更新特定端点的ACL。

典型的更新如下所示:

<?xml version="1.0"?>
<PersistentVMRole xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ConfigurationSets>
    <ConfigurationSet>
        <ConfigurationSetType>NetworkConfiguration</ConfigurationSetType>
        <InputEndpoints>
            <InputEndpoint>
                <LocalPort>100</LocalPort>
                <Name>TCP-100</Name>
                <Port>100</Port>
                <Protocol>tcp</Protocol>
                <EndpointACL>
            <Rules>
              <Rule>
                <Order>1</Order>
                <Action>deny</Action>
                <RemoteSubnet>108.239.229.0/24</RemoteSubnet>
                <Description>test-rule</Description>
              </Rule>
            </Rules>
          </EndpointACL>
            </InputEndpoint>
        </InputEndpoints>
        <SubnetNames>
            <SubnetName>Subnet-1</SubnetName>
        </SubnetNames>
    </ConfigurationSet>
</ConfigurationSets>
</PersistentVMRole>