Format for POST request body

RESTful knowledge exchange

Format for POST request body

Veeam Logoby Alim » Sun Apr 12, 2015 8:32 am

Hi All

I encountered an error trying to perform a POST command with a request body input as a String type,

<Error Message="Unable to deserialize XML body with root name 'Binary' and root namespace '' (for operation 'CreateObjectInJob' and contract ('IEnterpriseRestService', 'http://www.veeam.com/ent/v1.0')) using XmlSerializer.

Is there any specific format to be used to post the XML body? Can we just define the XML body as a string value and use it as input for the POST command? Will it work that way?

Can advise.

Thanks.

Regards
Alim.
Alim
Novice
 
Posts: 5
Liked: never
Joined: Sun Mar 11, 2012 5:49 am
Full Name: Mohammad Alim

Re: Format for POST request body

Veeam Logoby Alim » Mon Apr 13, 2015 3:39 am

Additional info with regards to the above, i am trying to use VMware Orchestrator (vco) to automate adding the VM to the job.

Workflow script

var requestContent = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<CreateObjectInJobSpec xmlns=\"http://www.veeam.com/ent/v1.0\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
"<HierarchyObjRef>urn:VMware:VM:5a12aea1-e48f-4bc5-85cd-59a8444a4acf.vm-645</HierarchyObjRef>" +
"<HierarchyObjName>backupclient1</HierarchyObjName>" +
"<Order>0</Order>" +
"<GuestProcessingOptions>" +
"<AppAwareProcessingMode>RequireSuccess</AppAwareProcessingMode>" +
"<FileSystemIndexingMode>ExceptSpecifiedFolders</FileSystemIndexingMode>" +
"<IncludedIndexingFolders/>" +
"<ExcludedIndexingFolders>" +
"<Path>%windir%</Path>" +
"<Path>%ProgramFiles%</Path>" +
"<Path>%TEMP%</Path>" +
"</ExcludedIndexingFolders>" +
"<CredentialsId/>" +
"</GuestProcessingOptions>" +
"</CreateObjectInJobSpec>";

var requestType = "POST";
var operationUrl = ""/jobs/aae2a6b-d3af-4b0c-b5fc-6b9c45206eeb/includes"
var request = restHost.createRequest(requestType, operationUrl, requestContent);

Error message

2015-04-13 11:00:10.089] [I] <?xml version="1.0" encoding="utf-8"?><Error Message="Unable to deserialize XML body with root name 'Binary' and root namespace '' (for operation 'CreateObjectInJob' and contract ('IEnterpriseRestService', 'http://www.veeam.com/ent/v1.0')) using XmlSerializer. Ensure that the type corresponding to the XML is added to the known types collection of the service." StatusCode="500" xmlns="http://www.veeam.com/ent/v1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><FirstChanceExceptionMessage>Unable to deserialize XML body with root name 'Binary' and root namespace '' (for operation 'CreateObjectInJob' and contract ('IEnterpriseRestService', 'http://www.veeam.com/ent/v1.0')) using XmlSerializer. Ensure that the type corresponding to the XML is added to the known types collection of the service.</FirstChanceExceptionMessage><StackTrace>Veeam.Backup.Interaction.RestAPI.CRestAPICommunicationException: Unable to deserialize XML body with root name 'Binary' and root namespace '' (for operation 'CreateObjectInJob' and contract ('IEnterpriseRestService', 'http://www.veeam.com/ent/v1.0')) using XmlSerializer. Ensure that the type corresponding to the XML is added to the known types collection of the service. ---> System.Runtime.Serialization.SerializationException: Unable to deserialize XML body with root name 'Binary' and root namespace '' (for operation 'CreateObjectInJob' and contract ('IEnterpriseRestService', 'http://www.veeam.com/ent/v1.0')) using XmlSerializer. Ensure that the type corresponding to the XML is added to the known types collection of the service.&#xD;
at System.ServiceModel.Dispatcher.SingleBodyParameterMessageFormatter.ReadObject(Message message)&#xD;
at System.ServiceModel.Dispatcher.SingleBodyParameterMessageFormatter.DeserializeRequest(Message message, Object[] parameters)&#xD;
at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters)&#xD;
at Veeam.Backup.Enterprise.RestAPIService.FormsPostDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters)&#xD;
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc&amp; rpc)&#xD;
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)&#xD;
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)&#xD;
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc)&#xD;
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)&#xD;
--- End of inner exception stack trace ---</StackTrace></Error>
Alim
Novice
 
Posts: 5
Liked: never
Joined: Sun Mar 11, 2012 5:49 am
Full Name: Mohammad Alim

Re: Format for POST request body

Veeam Logoby greenhoorn » Tue Apr 14, 2015 7:22 am 1 person likes this post

Did you specify the ContentType-header? Take a look at the "must-have"-headers here: http://helpcenter.veeam.com/backup/80/rest/
greenhoorn
Service Provider
 
Posts: 14
Liked: 1 time
Joined: Fri Mar 20, 2015 3:45 pm
Location: Switzerland
Full Name: Joel Neutzner

Re: Format for POST request body

Veeam Logoby Alim » Tue Apr 14, 2015 1:25 pm

Yes, the header has been specified as "Content-Type" and "application/xml".

Thanks.
Alim
Novice
 
Posts: 5
Liked: never
Joined: Sun Mar 11, 2012 5:49 am
Full Name: Mohammad Alim

Re: Format for POST request body

Veeam Logoby Alim » Tue Apr 21, 2015 3:35 am

greenhoorn wrote:Did you specify the ContentType-header? Take a look at the "must-have"-headers here: http://helpcenter.veeam.com/backup/80/rest/


I used my own script to post the header instead of the built-in script, and it works now. Thanks.
Alim
Novice
 
Posts: 5
Liked: never
Joined: Sun Mar 11, 2012 5:49 am
Full Name: Mohammad Alim


Return to RESTful API



Who is online

Users browsing this forum: No registered users and 5 guests