private void SendNotify(Dialog dialog, int expires, PresenceDocument document) { int transactionId = GetTransactionId(Methods.Notifym); var writer = new SipMessageWriter(); writer.WriteRequestLine(Methods.Notifym, dialog.RemoteUri); writer.WriteVia(dialog.Transport, dialog.LocalEndPoint, transactionId); writer.WriteFrom(dialog.LocalUri, dialog.LocalTag); writer.WriteTo(dialog.RemoteUri, dialog.RemoteTag); writer.WriteCallId(dialog.CallId); writer.WriteEventPresence(); writer.WriteSubscriptionState(expires); writer.WriteMaxForwards(70); writer.WriteCseq(dialog.GetNextLocalCseq(), Methods.Notifym); writer.WriteContact(dialog.LocalEndPoint, dialog.Transport); if (document != null) { writer.WriteContentType(application, pidfXml); //writer.WriteContentLength(); //writer.WriteCRLF(); //writer.RewriteContentLength( // document.CopyTo((length) => writer.GetBytesForCustomWrite(length))); document.WriteLenghtAndContent(writer); } else { writer.WriteContentLength(0); writer.WriteCRLF(); } notifyProducer.SendRequest(dialog.Transport, dialog.LocalEndPoint, dialog.RemoteEndPoint, ServerAsyncEventArgs.AnyConnectionId, writer, transactionId); }