rubysavonbing-ads-api

Bing ads api - savon error for get_ad_extensions_associations


Maintaining a gem to wrap bing ads api, I am using this wsdl from bing.

Most api calls work fine so far, but I am stumbling upon the get_ad_extensions_associations one.

What I type is:

client.call(
  :get_ad_extensions_associations, 
  message: { account_id: 150168726, association_type: "Campaign", ad_extension_type: "CallAdExtension", entity_ids: [ { long: 8177659860409 }] },
  soap_header: header
)

What is sent to bing is the following:

I, [2019-01-10T11:33:52.222852 #19132]  INFO -- : SOAP request: https://campaign.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/V12/CampaignManagementService.svc
I, [2019-01-10T11:33:52.222951 #19132]  INFO -- : SOAPAction: "GetAdExtensionsAssociations", Content-Type: text/xml;charset=UTF-8, Content-Length: 2152
D, [2019-01-10T11:33:52.223282 #19132] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="https://bingads.microsoft.com/CampaignManagement/v12" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:ins1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" xmlns:ins2="http://schemas.datacontract.org/2004/07/System" xmlns:ins3="https://adapi.microsoft.com">
  <env:Header>
    <tns:AuthenticationToken>***FILTERED***</tns:AuthenticationToken>
    <tns:DeveloperToken>***FILTERED***</tns:DeveloperToken>
    <tns:CustomerId>***FILTERED***</tns:CustomerId>
    <tns:CustomerAccountId>***FILTERED***</tns:CustomerAccountId>
  </env:Header>
  <env:Body>
    <tns:GetAdExtensionsAssociationsRequest>
      <tns:AccountId>150168726</tns:AccountId>
      <tns:AdExtensionType>CallAdExtension</tns:AdExtensionType>
      <tns:AssociationType>Campaign</tns:AssociationType>
      <tns:EntityIds>
        <tns:long>8177659860409</tns:long>
      </tns:EntityIds>
    </tns:GetAdExtensionsAssociationsRequest>
  </env:Body>
</env:Envelope>

What I get back is the following:

D, [2019-01-10T11:33:52.223406 #19132] DEBUG -- : HTTPI /peer POST request to campaign.api.bingads.microsoft.com (excon)
I, [2019-01-10T11:33:52.906376 #19132]  INFO -- : SOAP response (status 500)
D, [2019-01-10T11:33:52.907343 #19132] DEBUG -- : <?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <s:Fault>
      <faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:DeserializationFailed</faultcode>
      <faultstring xml:lang="en-US">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:EntityIds. The InnerException message was 'There was an error deserializing the object of type System.Int64[]. End element 'EntityIds' from namespace 'https://bingads.microsoft.com/CampaignManagement/v12' expected. Found element 'tns:long' from namespace 'https://bingads.microsoft.com/CampaignManagement/v12'. Line 1, position 2046.'.  Please see InnerException for more details.</faultstring>
      <detail>
        <ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
          <HelpLink i:nil="true"/>
          <InnerException>
            <HelpLink i:nil="true"/>
            <InnerException>
              <HelpLink i:nil="true"/>
              <InnerException i:nil="true"/>
              <Message>End element 'EntityIds' from namespace 'https://bingads.microsoft.com/CampaignManagement/v12' expected. Found element 'tns:long' from namespace 'https://bingads.microsoft.com/CampaignManagement/v12'. Line 1, position 2046.</Message>
              <StackTrace>   at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)&#xD;
   at System.Xml.XmlExceptionHelper.ThrowEndElementExpected(XmlDictionaryReader reader, String localName, String ns)&#xD;
   at System.Xml.XmlBaseReader.ReadEndElement()&#xD;
   at System.Runtime.Serialization.CollectionDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)&#xD;
   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract&amp; dataContract)&#xD;
   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns)&#xD;
   at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName, DataContractResolver dataContractResolver)&#xD;
   at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)</StackTrace>
              <Type>System.Xml.XmlException</Type>
            </InnerException>
            <Message>There was an error deserializing the object of type System.Int64[]. End element 'EntityIds' from namespace 'https://bingads.microsoft.com/CampaignManagement/v12' expected. Found element 'tns:long' from namespace 'https://bingads.microsoft.com/CampaignManagement/v12'. Line 1, position 2046.</Message>
            <StackTrace>   at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)&#xD;
   at System.Runtime.Serialization.DataContractSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName)&#xD;
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.PartInfo.ReadObject(XmlDictionaryReader reader, XmlObjectSerializer serializer)&#xD;
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)</StackTrace>
            <Type>System.Runtime.Serialization.SerializationException</Type>
          </InnerException>
          <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:EntityIds. The InnerException message was 'There was an error deserializing the object of type System.Int64[]. End element 'EntityIds' from namespace 'https://bingads.microsoft.com/CampaignManagement/v12' expected. Found element 'tns:long' from namespace 'https://bingads.microsoft.com/CampaignManagement/v12'. Line 1, position 2046.'.  Please see InnerException for more details.</Message>
          <StackTrace>   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)&#xD;
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameters(XmlDictionaryReader reader, PartInfo[] parts, Object[] parameters, Boolean isRequest)&#xD;
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)&#xD;
   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)&#xD;
   at System.ServiceModel.Dispatcher.OperationFormatter.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.ProcessMessage11(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace>
          <Type>System.ServiceModel.Dispatcher.NetDispatcherFaultException</Type>
        </ExceptionDetail>
      </detail>
    </s:Fault>
  </s:Body>
</s:Envelope>

Documentation for the action is there but the gem is supposed to wrap everything properly as it does for the other actions I tried.

In the end I do not know where to debug as it seems to be internal handling of the wsdl.


Solution

  • It has been a long time since I worked with soap but if you know that the namespace is the problem then I'd just write 'ins0:long' => <number> instead of long:<number>. That's how I circumvent those problems.