BingAds / BingAds-Python-SDK

Other
117 stars 162 forks source link

DeleteCampaignsRequest type error, refuses long as CampaignId argument #97

Closed michauds closed 6 years ago

michauds commented 6 years ago

I'm trying to delete some campaigns in the sandbox environment. I'm getting a conflict with the namespaces and suds while using the factory to generate a list of campaigns ids to send in the request.

envelope with namespaces:

snippet of soap body with fake values:

      <ns1:DeleteCampaignsRequest>
         <ns1:AccountId>098765</ns1:AccountId>
         <ns1:CampaignIds>
            <ns2:long>123456</ns2:long>
         </ns1:CampaignIds>
      </ns1:DeleteCampaignsRequest>
   </ns0:Body>

snippet of code used to generate the arguments:

campaign_ids = client.factory.create('CampaignIds')
campaign_ids.long.append(123456)

soap fault:

   faultcode = "a:DeserializationFailed"
   faultstring = "The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter https://bingads.microsoft.com/CampaignManagement/v12:CampaignIds. The InnerException message was 'There was an error deserializing the object of type System.Int64[]. End element 'CampaignIds' from namespace 'https://bingads.microsoft.com/CampaignManagement/v12' expected. Found element 'ns2:long' from namespace 'http://schemas.datacontract.org/2004/07/System'. Line 1, position 1809.'.  Please see InnerException for more details."
   detail = 
      (detail){
         ExceptionDetail = 
            (ExceptionDetail){
               HelpLink = None
               InnerException = 
                  (InnerException){
                     HelpLink = None
                     InnerException = 
                        (InnerException){
                           HelpLink = None
                           InnerException = None
                           Message = "End element 'CampaignIds' from namespace 'https://bingads.microsoft.com/CampaignManagement/v12' expected. Found element 'ns2:long' from namespace 'http://schemas.datacontract.org/2004/07/System'. Line 1, position 1809."
                           StackTrace = "   at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
   at System.Xml.XmlExceptionHelper.ThrowEndElementExpected(XmlDictionaryReader reader, String localName, String ns)
   at System.Xml.XmlBaseReader.ReadEndElement()
   at System.Runtime.Serialization.CollectionDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns)
   at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
   at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)"
                           Type = "System.Xml.XmlException"
                        }
                     Message = "There was an error deserializing the object of type System.Int64[]. End element 'CampaignIds' from namespace 'https://bingads.microsoft.com/CampaignManagement/v12' expected. Found element 'ns2:long' from namespace 'http://schemas.datacontract.org/2004/07/System'. Line 1, position 1809."
                     StackTrace = "   at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
   at System.Runtime.Serialization.DataContractSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName)
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.PartInfo.ReadObject(XmlDictionaryReader reader, XmlObjectSerializer serializer)
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)"
                     Type = "System.Runtime.Serialization.SerializationException"
                  }
               Message = "The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter https://bingads.microsoft.com/CampaignManagement/v12:CampaignIds. The InnerException message was 'There was an error deserializing the object of type System.Int64[]. End element 'CampaignIds' from namespace 'https://bingads.microsoft.com/CampaignManagement/v12' expected. Found element 'ns2:long' from namespace 'http://schemas.datacontract.org/2004/07/System'. Line 1, position 1809.'.  Please see InnerException for more details."
               StackTrace = "   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameters(XmlDictionaryReader reader, PartInfo[] parts, Object[] parameters, Boolean isRequest)
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)
   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)"
               Type = "System.ServiceModel.Dispatcher.NetDispatcherFaultException"
            }
      }
 }

According to the shopping campaign example, this should work. However, the fault says the argument must be of type CampaignId from namespace "https://bingads.microsoft.com/CampaignManagement/v12" and the reference documentations says it must be a long from namespace "http://schemas.microsoft.com/2003/10/Serialization/Arrays".

Can you please confirm the expected type and correct the documentation? Thanks.

michauds commented 6 years ago

After further investigation, it seems the documentation is correct and not the pricing example In order to generate the XML with the proper namespace, I needed to do the following call

campaigns = factory.create('ns3:ArrayOflong')
campaigns.long.append(12345)

Hope it helps.