开发者

Management API - The request body XML was invalid or not correctly specified

Cross posting from http://social.msdn.microsoft.com/Forums/en-US/windowsazuretroubleshooting/thread/31b6aedc-c069-4e32-8e8f-2ff4b7c30793

I'm getting this error on changing configuration through the service management API: The request body XML was invalid or not correctly specified

The request body payload:

<?xml version="1.0" encoding="utf-8"?>
<ChangeConfiguration xmlns="http://schemas.microsoft.com/windowsazu
re">
  <Configuration>PD94bWwgdmVyc2lvbj0iMS4wIj8+CjxTZXJ2aWNlQ29uZmlndX
JhdGlvbiB4bWxuczp4c2k9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIi
B4bWxuczp4c2Q9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hIiB4bWxucz0iaHR0cDovL3
NjaGVtYXMubWljcm9zb2Z0LmNvbS9TZXJ2aWNlSG9zdGluZy8yMDA4LzEwL1NlcnZpY2VDb25maWd1cm
F0aW9uIiBzZXJ2aWNlTmFtZT0iIiBvc0ZhbWlseT0iMSIgb3NWZXJzaW9uPSIqIj4KICA8Um9sZSBuYW
1lPSJXZWJSb2xlMSI+CiAgICA8Q29uZmlndXJhdGlvblNldHRpbmdzPgogICAgICA8U2V0dGluZyBuYW
1lPSJNaWNyb3NvZnQuV2luZG93c0F6dXJlLlBsdWdpbnMuRGlhZ25vc3RpY3MuQ29ubmVjdGlvblN0cm
luZyIgdmFsdWU9IlVzZURldmVsb3BtZW50U3RvcmFnZT10cnVlIi8+CiAgICA8L0NvbmZpZ3VyYXRpb2
5TZXR0aW5ncz4KICAgIDxJbnN0YW5jZXMgY291bnQ9IjIiLz4KICAgIDxDZXJ0aWZpY2F0ZXMvPgogID
wvUm9sZT4KPC9TZXJ2aWNlQ29uZmlndXJhdGlvbj4K</Configuration>
</ChangeConfiguration>

I'm passing it the following configuration:

$configuration = '<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" serviceName="" osFamily="1" osVersion="*">
 <Role name="WebRole1">
  <ConfigurationSettings>
   <Setting name="Microsoft.WindowsAzure.Plugins.Diagnosti开发者_运维知识库cs.ConnectionString" value="UseDevelopmentStorage=true"/>
  </ConfigurationSettings>
  <Instances count="2"/>
  <Certificates/>
 </Role>
</ServiceConfiguration>';

Does anyone know why this error occurs? I suspect it has something to do with encoding but not sure.


Are you getting this directly from the call to the API? If so, it should be coming back with a x-ms-requestid header.

If you take that and call out to

https://management.core.windows.net/<subscriptionID/operations/<requestId>

This should give you a much more detailed message about what is going on, usually telling you exactly what is going on.

Outside of that, I'd check the following:

1.) Check your encoding, then check it again. I only mention this because when I first wrapped the API I had an issue where my encoding was screwing something up. So what I finally did was write a bit of code that would read the file, encode it, decode that, save that to a new file. Then binary compare the two. I finally found they were different by a single byte and it broke the whole thing.

2.) Check your config. Upload that exact config file to your role via the portal and see if its accepted.

3.) Check API version header. Not sure on the SDK for PHP, but if possible can you explicitly check/set the x-ms-version header being sent to the api?

4.) Cause a valid failure, and reverse engineer from there. If all else fails, pass in a blank or random/invalid encoded string. Then use the GetOperationStatus endpoint to ensure you are getting errors to the tune of "Configuration is invalid". This way you know your request is being accepted, but the encoding/configuration is throwing an error.

EDIT: from your reply here and MSDN

5.) Try omitting the XML Declaration

<?xml version="1.0" encoding="utf-8"?>

from the request body. When I run your exact request vs the same request created by my own .net api wrapper, the only difference is that XML declaration is not in the body of the POST. The wrapper-generated class works for me.


Thanks everyone! I've been reverse-engineering what the csmanage.exe sends over the wire, and it works now. Here's why:

  • Steve Marx' "/" solution (http://social.msdn.microsoft.com/Forums/en-US/windowsazuretroubleshooting/thread/31b6aedc-c069-4e32-8e8f-2ff4b7c30793?prof=required) was required (it should be: //services/hostedservices/phptest1/deploymentslots/production/?comp=config)
  • I removed the XML declaration
  • I had to replace all newlines in my XML and make it a one-liner

As a side note: I noticed there's a "x-ms-version: 2010-04-01" in csmanage.exe. Any news/docs on that version?

PS: This will end up in the Windows Azure SDK for PHP if you want to see it working


1) Getting the config from Azure as ASCII (?), uploading it again as ASCII fails, uploading it as UTF-8 fails as well.

2) Works

3) Works

4) All I get is this lausy error (should create a T-Shirt from that :-)): "The request body XML was invalid or not correctly specified", even when passing it an ampty XML.

For the record: RAW request and response are:

-----------------------
Request
-----------------------

object(Microsoft_Http_Client)#3 (15) {
  ["adapter:protected"]=>
  object(Microsoft_Http_Client_Adapter_Socket)#5 (6) {
    ["socket:protected"]=>
    NULL
    ["connected_to:protected"]=>
    array(2) {
      [0]=>
      NULL
      [1]=>
      NULL
    }
    ["out_stream:protected"]=>
    NULL
    ["config:protected"]=>
    array(15) {
      ["persistent"]=>
      bool(false)
      ["ssltransport"]=>
      string(3) "ssl"
      ["sslcert"]=>
      string(51) "C:\Projects\Workspaces\Default\Azure\management.pem"
      ["sslpassphrase"]=>
      string(11) "*************"
      ["maxredirects"]=>
      int(5)
      ["strictredirects"]=>
      bool(false)
      ["useragent"]=>
      string(21) "Microsoft_Http_Client"
      ["timeout"]=>
      int(10)
      ["httpversion"]=>
      string(3) "1.1"
      ["keepalive"]=>
      bool(false)
      ["storeresponse"]=>
      bool(true)
      ["strict"]=>
      bool(true)
      ["output_stream"]=>
      bool(false)
      ["sslusecontext"]=>
      bool(true)
    }
    ["method:protected"]=>
    string(3) "POST"
    ["_context:protected"]=>
    resource(38) of type (stream-context)
  }
  ["uri:protected"]=>
  object(Microsoft_Uri_Http)#10 (9) {
    ["_username:protected"]=>
    string(0) ""
    ["_password:protected"]=>
    string(0) ""
    ["_host:protected"]=>
    string(27) "management.core.windows.net"
    ["_port:protected"]=>
    int(443)
    ["_path:protected"]=>
    string(97) "/******************/services/hostedservices/phptest1/deploymentslots/production"
    ["_query:protected"]=>
    string(11) "comp=config"
    ["_fragment:protected"]=>
    string(0) ""
    ["_scheme:protected"]=>
    string(5) "https"
  }
  ["headers:protected"]=>
  array(3) {
    ["content-type"]=>
    array(2) {
      [0]=>
      string(12) "Content-Type"
      [1]=>
      string(15) "application/xml"
    }
    ["expect"]=>
    array(2) {
      [0]=>
      string(6) "Expect"
      [1]=>
      string(0) ""
    }
    ["x-ms-version"]=>
    array(2) {
      [0]=>
      string(12) "x-ms-version"
      [1]=>
      string(10) "2009-10-01"
    }
  }
  ["method:protected"]=>
  string(3) "POST"
  ["paramsGet:protected"]=>
  array(0) {
  }
  ["paramsPost:protected"]=>
  array(0) {
  }
  ["enctype:protected"]=>
  NULL
  ["raw_post_data:protected"]=>
  string(965) "<?xml version="1.0" encoding="utf-8"?>
             <ChangeConfiguration xmlns="http://schemas.microsoft.com/windowsazure">
               <Configuration>PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPFNlcnZpY2VDb25maWd1cmF0aW9uIHhtbG5zOnhzaT0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEtaW5zdGFuY2UiIHhtbG5zOnhzZD0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEiIHhtbG5zPSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL1NlcnZpY2VIb3N0aW5nLzIwMDgvMTAvU2VydmljZUNvbmZpZ3VyYXRpb24iIHNlcnZpY2VOYW1lPSIiIG9zRmFtaWx5PSIxIiBvc1ZlcnNpb249IioiPgogIDxSb2xlIG5hbWU9IldlYlJvbGUxIj4KICAgIDxDb25maWd1cmF0aW9uU2V0dGluZ3M+CiAgICAgIDxTZXR0aW5nIG5hbWU9Ik1pY3Jvc29mdC5XaW5kb3dzQXp1cmUuUGx1Z2lucy5EaWFnbm9zdGljcy5Db25uZWN0aW9uU3RyaW5nIiB2YWx1ZT0iVXNlRGV2ZWxvcG1lbnRTdG9yYWdlPXRydWUiLz4KICAgIDwvQ29uZmlndXJhdGlvblNldHRpbmdzPgogICAgPEluc3RhbmNlcyBjb3VudD0iMiIvPgogICAgPENlcnRpZmljYXRlcy8+CiAgPC9Sb2xlPgo8L1NlcnZpY2VDb25maWd1cmF0aW9uPgo=</Configuration>
             </ChangeConfiguration>"
  ["auth:protected"]=>
  NULL
  ["files:protected"]=>
  array(0) {
  }
  ["cookiejar:protected"]=>
  NULL
  ["last_request:protected"]=>
  NULL
  ["last_response:protected"]=>
  NULL
  ["redirectCounter:protected"]=>
  int(0)
}

-----------------------
Response
-----------------------
object(Microsoft_Http_Response)#9 (5) {
  ["version:protected"]=>
  string(3) "1.1"
  ["code:protected"]=>
  int(400)
  ["message:protected"]=>
  string(11) "Bad Request"
  ["headers:protected"]=>
  array(5) {
    ["Content-length"]=>
    string(3) "230"
    ["Content-type"]=>
    string(30) "application/xml; charset=utf-8"
    ["Server"]=>
    string(21) "Microsoft-HTTPAPI/2.0"
    ["Date"]=>
    string(29) "Thu, 17 Feb 2011 07:15:36 GMT"
    ["Connection"]=>
    string(5) "close"
  }
  ["body:protected"]=>
  string(230) "<Error xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Code>InvalidXmlRequest</Code><Message>The request body’s XML was invalid or not correctly specified.</Message></Error>"
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜