Git Product home page Git Product logo

dotamf's Introduction

NuGet packages: DotAmf (serializer) and DotAmf.Wcf (service layer).

About

.NET serializer and WCF bindings for AMF with full Flex remoting support.

Action Message Format (AMF) is a binary format used to serialize object graphs such as ActionScript objects and XML, or send messages between an Adobe Flash client and a remote service, usually a Flash Media Server or third party alternatives. The Actionscript 3 language provides classes for encoding and decoding from the AMF format.

http://en.wikipedia.org/wiki/Action_Message_Format

AMF has several advantages over existing serialization formats, including the ability to maintain objects graph, a small footprint when storing a set of identical objects (including strings) or references to the same object, and a wide range of natively supported types (such as XmlDocument, DateTime and Dictionary).

WCF Configuration

Consider the following service contracts:

    using System;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Xml;

    namespace ExampleService
    {
        [ServiceContract]
        public interface IMyService
        {
            [OperationContract]
            ProductVo[] GetAllProducts();

            [OperationContract(Name = "GetUser")] //Custom procedure name
            User GetUserDataContract(int id);

            [OperationContract]
            int AddUser(User user);

            [OperationContract]
            Content SendContent(Content content);

            [OperationContract]
            User[] SendGraph(User[] users);

            [OperationContract]
            void DoStuff();

            [OperationContract]
            [FaultContract(typeof(CustomFault))]
            void DoFault();
        }

        [DataContract] //Will have the "ExampleService.User" alias
        public class User
        {
            [DataMember(Name = "id")] //Custom field name
            public int Id { get; set; }

            [DataMember(Name = "is_active")]
            public bool IsActive { get; set; }

            [DataMember] //Use explicit name
            public string name { get; set; }

            [DataMember(Name = "products")]
            public ProductVo[] Products { get; set; }
        }

        [DataContract(Name = "Product")] //Custom alias
        public class ProductVo
        {
            [DataMember(Name = "id")]
            public int Id { get; set; }
        }

        [DataContract]
        public class CustomFault
        {
            [DataMember(Name = "date")]
            public DateTime Date { get; set; }

            [DataMember(Name = "message")]
            public string Message { get; set; }
        }

        [DataContract]
        public class Content
        {
            [DataMember(Name = "data")]
            public byte[] Data { get; set; }

            [DataMember(Name = "xml")]
            public XmlDocument Xml { get; set; }
        }
    }

To add an AMF support to a service, you only need to update your configuration:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <extensions>
      <behaviorExtensions>
        <add name="amfBehaviorExtension" type="DotAmf.ServiceModel.Configuration.AmfBehaviorExtensionElement, DotAmf.Wcf"/>
      </behaviorExtensions>
      <bindingElementExtensions>
        <add name="amfBindingExtension" type="DotAmf.ServiceModel.Configuration.AmfBindingExtensionElement, DotAmf.Wcf"/>
      </bindingElementExtensions>
    </extensions>
    <behaviors>
      <endpointBehaviors>
        <behavior name="amfEndpoint">
          <amfBehaviorExtension/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="amfServiceBehavior">
          <serviceMetadata httpGetEnabled="false"/>
          <serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <customBinding>
        <binding name="amfBinding">
          <amfBindingExtension/>
          <httpTransport/>
        </binding>
      </customBinding>
    </bindings>
    <services>
      <service name="ExampleService.MyService" behaviorConfiguration="amfServiceBehavior">
        <endpoint address="" contract="ExampleService.IMyService" binding="customBinding" bindingConfiguration="amfBinding" behaviorConfiguration="amfEndpoint"/>
      </service>
    </services>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="false"/>
  </system.webServer>
</configuration>

See the Examples folder for a complete service and client implementations.

Serialization

You can use DataContractAmfSerializer to serialize and deserialize from binary AMF data outside of the WCF.

CustomType objectToWrite;

var knownTypes = new[] {
    typeof(KnownType1),
    typeof(KnownType2)
};
var serializer = new DataContractAmfSerializer(typeof(CustomType), knownTypes);

using (var stream = new MemoryStream())
    serializer.WriteObject(stream, objectToWrite);

dotamf's People

Contributors

artema avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dotamf's Issues

WebAPI

Hi Artem,

This lib looks great! I'm fairly new to using github, so apologies for using the Issues panel to message you, but here goes:

In Microsoft Web API (their latest form of web service), it is possible to create MediaTypeFormatters that allow Web API to respond to a client in a different protocol / response / content type.

I am looking at trying to implement an AMFMediaTypeFormatter, which would basically accept requests and respond in AMF to the client. This way we can get round-trip serialisation between POCOs and AS3 classes over MS WebAPI.

Have you heard of WebAPI? Does this sound like a good plan?

Cheers,
Ben

AMF3 decoding outputting illegal XML characters

I'm using dotAMF to decode some AMF3 data, and I was getting 'illiegal character 1e' errors when trying to get the XML for my AMF. I added a bit of code to AMF3Decoder.cs to to clean the invalid characters, and everything is now working fine. Do you want this change, am I doing something wrong, or should I put the change in somehow?

Amf3Decoder.zip

Thanks,
jason

Any change to port to .NET Core ?

I see that DotAmf it's .NET Core compatible by himself but DotAmf.Wcf is not because the WCF client side dependency but not that much.
It's possible to port to .NET Core ?

Is Amfx official standard format?

Hi, i find your code can decode Stream data to XmlWriter, it will create a xml with amfx tag, is amfx format have official description document ? or this format create by yourself ?

how to make login

how do i create login from flash ?? does it has a function or library for authentication ??

Argument Count Mismatch

I send a request from flex, like this
var token:AsyncToken = remoteObject.getOperation("MyMethod").send("Arg1");

but it fault with "Argument Count Mismatch"

I trace the code find issue in class
DotAmf.ServiceModel.Dispatcher.AmfGenericOperationFormatter

at line 53
var args = input[0] as IList;
if (args == null || args.Count != parameters.Length)
throw new InvalidOperationException(Errors.AmfGenericOperationFormatter_DeserializeRequest_ArgumentCountMismatch);

I don't know why convert input[0] as IList, but if i change the code as below, it worked
var args = input as IList;

does amf push message support?

I can't find how to consumer a amf message in examples.
there is only using s:RemoteObject, and says destination not supported.
so, s:Consumer not supported yet ?

anyway, thanks for this work.

XmlException - Element node expected, when array is empty

have a complex object to return. like following class
Class A {
public string Name;
public ClassB[] Children;
}
when serialize class a.Children ClassB array length = 0, this exception will be throw...

This issue can be fixed in
DotAmf.Encoder.Amf3Encoder.WriteArray
move line 403 input.Read(); after line 414 if (length == 0) return;
... should like below

        if (length == 0) return;
        input.Read(); // move here from line 403

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.