2012-03-18 83 views
3

我的问题是,当我尝试获取对我的HTTP请求的响应时,我收到了400错误的请求。 任何人都可以告诉我为什么会发生这种情况,可能我该如何解决它?400错误的请求,Azure服务管理API配置更改

确切的错误是: BadRequest在设置无变化指定

我把一个断点在我的代码之前,我在配置文件中传递,当我看到它,它改变了什么,我想它改变所以已经存在的配置文件对于我正在尝试改变的配置文件来说有点不同。

下面是配置更改API的信息:http://msdn.microsoft.com/en-us/library/windowsazure/ee460809.aspx

而下面是我的代码,任何帮助是极大的赞赏,谢谢

public void changeConfiguration(string serviceName, string deploymentSlot, string config, string deploymentName) 
{ 
//encoding the config file 
    byte[] encodedConfigbyte = new byte[config.Length]; 
    encodedConfigbyte = System.Text.Encoding.UTF8.GetBytes(config); 
    string temp = Convert.ToBase64String(encodedConfigbyte); 

//creating the URI with the subscriptionID,serviceName and deploymentSlot 
    Uri changeConfigRequestUri = new Uri("https://management.core.windows.net/" + subscriptionId + "/services/hostedservices/" + serviceName + "/deploymentslots/" + deploymentSlot + "/?comp=config"); 

//creating a request using the URI 
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(changeConfigRequestUri); 

//Adding a header to the request 
    request.Headers.Add("x-ms-version", "2010-10-28"); 
    request.Method = "POST"; 

//Create a string to hold the request body, temp being the config file 
    string bodyText = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
         "<ChangeConfiguration xmlns=\"http://schemas.microsoft.com/windowsazure\"" + ">" 
         + "<Configuration>" + temp + "</Configuration></ChangeConfiguration>"; 

//encoding the body 
    byte[] buf = Encoding.ASCII.GetBytes(bodyText); 
    request.ContentType = "application/xml"; 
    request.ContentLength = buf.Length; 

//searches the cert store for a cert that has a matching thumbprint to the thumbprint supplied 
    X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser); 
    try 
    { 
     certStore.Open(OpenFlags.ReadOnly); 
    } 
    catch (Exception e) 
    { 
     if (e is CryptographicException) 
     { 
      Console.WriteLine("Error: The store is unreadable."); 
     } 
     else if (e is SecurityException) 
     { 
      Console.WriteLine("Error: You don't have the required permission."); 
     } 
     else if (e is ArgumentException) 
     { 
      Console.WriteLine("Error: Invalid values in the store."); 
     } 
     else 
     { 
      throw; 
     } 
    } 
    X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false); 
    certStore.Close(); 
    if (certCollection.Count == 0) 
    { 
     throw new Exception("Error: No certificate found containing thumbprint "); 
    } 
    X509Certificate2 certificate = certCollection[0]; 

//cert is added to the request 
request.ClientCertificates.Add(certificate); 

//the requestBody is written to the request 
    Stream dataStream = request.GetRequestStream(); 
    dataStream.Write(buf, 0, buf.Length); 
    dataStream.Close(); 
    try 
    { 
    //retrieving responce 
     WebResponse response = (HttpWebResponse)request.GetResponse(); 
    } 
    catch (WebException e) 
    { 
     string test = new StreamReader(e.Response.GetResponseStream()).ReadToEnd(); 
    } 
} 

}

+0

您可能想将您的解决方案与[msdn上的示例代码](http://msdn.microsoft.com/zh-cn/library/ee460795.aspx) – 2012-03-19 07:34:37

回答

1

错误请求意味着一个参数是不正确。我的猜测是,您使用的是0,而不是分期或生产deploymentSlot喜欢这里提到:

http://msdn.microsoft.com/en-us/library/ee460786.aspx

其他则是,这将是巨大的,如果你能告诉我们您的传入参数我们也许可以从中发现什么是错的。

相关问题