unable to send push notifications using FCM/GCM

RamprasadKRamprasadK USMember ✭✭
edited October 2017 in Cross Platform with Xamarin

Here is my api code and i followed this link/plugin

https://github.com/CrossGeeks/FirebasePushNotificationPlugin

    [Route("api/User/SendNotification")]
    public async Task<IFCMResponse> SendPushNotification()
    {
        FCMClient client = new FCMClient("AIzaSyA7noakwGqktYESGjqtd66M98jR_c_JZ_4");  //legacy server key

        var message = new Message()
        {
            To = "/topics/all", //topic example /topics/all   // to send notifications for all devices, Is this Right?
            Notification = new AndroidNotification()
            {
                Body = "Hello World",
                Title = "MyApp",
                Sound ="Default"
            },

            Data = new Dictionary<string, string>
            {
                { "number", "1" },
                { "count", "10" }
            }
        };

       IFCMResponse  result = await client.SendMessageAsync(message);
        return result ;
    }

How to register devices and get register ids

This is the error i got when i run the webapi


An error has occurred.

The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'.

System.InvalidOperationException


An error has occurred.

Type 'FirebaseNet.Messaging.TopicMessageResponse' with data contract name 'TopicMessageResponse:http://schemas.datacontract.org/2004/07/FirebaseNet.Messaging' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer.


System.Runtime.Serialization.SerializationException


at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, Boolean verifyKnownType, RuntimeTypeHandle declaredTypeHandle, Type declaredType) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiTypeAtTopLevel(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle originalDeclaredTypeHandle, Type graphType) at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver) at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver) at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver) at System.Runtime.Serialization.DataContractSerializer.WriteObject(XmlWriter writer, Object graph) at System.Net.Http.Formatting.XmlMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content) at System.Net.Http.Formatting.XmlMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Net.Http.HttpContent.d__44.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.WebHost.HttpControllerHandler.d__1b.MoveNext()


Sign In or Register to comment.