0
votes

I get the following error while trying to update CampaignCriterions for a Campaign using PHP SDK for Bing Ads Api.

While searching for a solution, I came across this code example and tried to encode Objects using SoapVar. I still get the same error. Maybe, I am missing something here. Any help on this will be wonderful.

Code

$criterion = new CampaignCriterion();
$criterion->CampaignId = $campaignCriterion->CampaignId;
$criterion->Criterion = $radiusCriterion;
$criterion->Id = $campaignCriterion->Id;
$criterion->Type = CampaignCriterionType::Radius;

$request = new UpdateCampaignCriterionsRequest();
$request->CampaignCriterions = [$criterion];

try {
    return $campaignManagementServiceProxy->GetService()->UpdateCampaignCriterions($request);   
} catch (SoapFault $se) {
    print_r($se);
}

Exception

[ExceptionDetail] => stdClass Object
(
    [HelpLink] => 
    [InnerException] => 
    [Message] => Cannot create an abstract class.
    [StackTrace] =>    
        at System.Runtime.Serialization.FormatterServices.nativeGetUninitializedObject(RuntimeType type)
        at ReadCampaignCriterionFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
        at System.Runtime.Serialization.ClassDataContract.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, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
        at ReadArrayOfCampaignCriterionFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString , XmlDictionaryString , CollectionDataContract )
        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)
        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)
        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.MemberAccessException
)

Update 09/26: Biddable Campaign Criterion The BiddableCampaignCriterion is added, and derives properties from the CampaignCriterion, which is now an abstract base class. You must use BiddableCampaignCriterion instead of CampaignCriterion in add, get, and update campaign criterion operations.

1

1 Answers

0
votes
  1. This occurs whenever Criterion, CriterionBid are not encrypted using SoapVar.
  2. Final CampaignCriterion should be encrypted as BiddableCampaignCriterion

Your final code should look like below (commented out old code):

$criterion = new CampaignCriterion();
// $criterion->CampaignId = $campaignCriterion->CampaignId;
$criterion = $campaignCriterion;

// $criterion->Criterion = $radiusCriterion;
$criterion->Criterion = new SoapVar($radiusCriterion, SOAP_ENC_OBJECT, 'RadiusCriterion', $campaignManagementServiceProxy->GetNamespace());

$criterion->Id = $campaignCriterion->Id;
// $criterion->Type = CampaignCriterionType::Radius; 
$criterion->CriterionBid = new SoapVar($campaignCriterion->CriterionBid, SOAP_ENC_OBJECT, 'BidMultiplier', $campaignManagementServiceProxy->GetNamespace());

$request = new UpdateCampaignCriterionsRequest();
// $request->CampaignCriterions = [$criterion];
$request->CampaignCriterions = [new SoapVar($criterion, SOAP_ENC_OBJECT, 'BiddableCampaignCriterion', $campaignManagementServiceProxy->GetNamespace());];

try {
    return $campaignManagementServiceProxy->GetService()->UpdateCampaignCriterions($request);   
} catch (SoapFault $se) {
    print_r($se);
}

References: - https://msdn.microsoft.com/en-us/library/bing-ads-campaign-management-radiuscriterion.aspx - https://msdn.microsoft.com/en-us/library/mt807658%28v=msads.110%29.aspx?f=255&MSPPError=-2147217396