web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Are there any full written samples about return DataContractAttribute Class from Service?

(0) ShareShare
ReportReport
Posted on by 900

Microsoft has again made Custom Services so hard to use what comes to returning Classes. If you want to build a Custom Service that is used by C# WCF Client it doesn't work without magic and weird tricks if you Service doesn't return basic variables.

Can't believe that what is so difficult to make standard Message handling so that Microsoft's other tools can use these Microsoft Custom Services.

Are there any full written samples or documents how to write a Custom Service returning a class with DataContractAttribute to WCF Client written in C#??

There  are dozen half written "infos" in this forum and Internet which doesn't say all needed phases to get this work.

Am I asking too much if I don't my every Custom Service returning a String or boolean??

What a Object Oriented Service Platform.

Best Regards,

Mike

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Mike Land Profile Picture
    900 on at
    RE: Are there any full written samples about return DataContractAttribute Class from Service?

    I solved this.

    When generating WCF client Proxy with svcutil the namespace above Dynamics.Ax.Application is wrong!!

    But when you create WCF client Proxy using Visual Studio namespace is different,     [System.Runtime.Serialization.KnownTypeAttribute(typeof(Rolex2012WebApp.AXServer.TETServicePersonContract))] and this compiles and works fine!

    So, my conclusion is that svcutil needs paramters to define different namespace that it does in default.

    Br

    Mike

  • Mike Land Profile Picture
    900 on at
    RE: Are there any full written samples about return DataContractAttribute Class from Service?

    Hello,

    I took a code snippet from reference.cs which is generated with svcutil.

    namespace Microsoft.Dynamics.Ax.Xpp
    {
    using System.Runtime.Serialization;


    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
    [System.Runtime.Serialization.DataContractAttribute(Name = "XppObjectBase", Namespace = "http://schemas.datacontract.org/2004/07/Microsoft.Dynamics.Ax.Xpp")]

    PROBLEM COMES FROM: typeof(Dynamics.Ax.Application.PersonNameContract.))


    [System.Runtime.Serialization.KnownTypeAttribute(typeof(Dynamics.Ax.Application.PersonNameContract.))]
    public partial class XppObjectBase : object, System.Runtime.Serialization.IExtensibleDataObject
    {

    And compiler error is :

    error CS0234: The type or namespace name 'Application' does not exist in the namespace 'Microsoft.Dynamics.Ax' (are you missing an assembly reference?)

    Br

    Mike

    ...

    Ant the compiler

  • Martin Dráb Profile Picture
    235,914 Most Valuable Professional on at
    RE: Are there any full written samples about return DataContractAttribute Class from Service?

    Please ignore my article for the moment. It's not about web service, it's about calling serialization from X++. It's a completely different topic.

    There is indeed nothing special about your data contract. I assume that your service class (which you haven't shown yet) is trivial as well, therefore I created my own service with your data contract and tried to reference it from applications.

    There was no issue at all with Windows applications (of course). You should try it as well, to see whether your service works in this environment.

    I got a minor issue in a MVC 5 Mobile application - the reference was generated empty until I unchecked "reusing types".

    Unfortunately I'm unable to reproduce your problem. Maybe it's time to reveal to us what exactly the error says.

  • Mike Land Profile Picture
    900 on at
    RE: Are there any full written samples about return DataContractAttribute Class from Service?

    My DataContract class in X++ is simple as It can be. Like below:

    No compiling errors anywhere in Custom service including compiling, deploying etc.

    [DataContractAttribute]

    public class PersonNameContract

    {

       str firstname;

       str lastname

       [DataMemberAttribute("FirstName")]

       public str parmFirstName(str _firstname = firstname)

       {

           firstname = _firstname;

           return firstname;

       }

       [DataMemberAttribute("LastName")]

       public str parmLastName(str _lastname = lastname)

       {

           lastname = _lastname;

           return lastname;

       }

    }

    like I'mentioned when I create WCF Client Proxy from WSDL it points to error where namespace Microsoft.Dynamics.Appication.PersonNameContract is mentioned.

    I have Dynamics AX 2012 R2 and Visual Studio 2013.

    I dont' use any features of AX in Visual Studio just trying to generate proxy class from WSDL into my ASP.NET MVC 5 Bootstrap Mobile Application.

    So, that should be work if AX's WSDL is standard.

    I also found your article below where you mention CIL, XML Serialization and Assemblies.

    community.dynamics.com/.../data-contract-serialization-from-x.aspx

    There was also articles which said that developer must copy CIL generated ?? Assemblies from AX into .NET WCF project. Didn't find that url now but is it really true?

    Yes, I'm bit worried because I should build a demo and this DataContractAtrribute has stucked me.

    Only way to avoid using DataContractAttribute/Class is to build a List and put member variables there... but that is not pure OOP at all and against to all good practices.

    If you can help I will appreciate it. And also my colleague in other company struggling with same problem.

    Br

    Mike

  • Martin Dráb Profile Picture
    235,914 Most Valuable Professional on at
    RE: Are there any full written samples about return DataContractAttribute Class from Service?

    I've never seen such a problem. Can you show us your service class? What's your version of AX and Visual Studio?

  • Martin Dráb Profile Picture
    235,914 Most Valuable Professional on at
    RE: Are there any full written samples about return DataContractAttribute Class from Service?

    I think that custom service are great and easy to use. You just define a data contract class in a similar way as in C#, return it from an X++ method and consume it in a WCF client as usual. It's great!

    Maybe you should calm down and explain us your problem. I might be willing to create an example for you, but you will have to be more specific.

  • Mike Land Profile Picture
    900 on at
    RE: Are there any full written samples about return DataContractAttribute Class from Service?

    Problem comes when creating a WCF client proxy from that Service's wsdl using svcutil or Visual Studio.

    It will not compile. WCF Proxy's reference to that DataContractClass is not found.

    I have spent days with this error and found similar topics without any case where problem has been solved.

  • Olof Wallin Profile Picture
    680 on at
    RE: Are there any full written samples about return DataContractAttribute Class from Service?

    Hi Mike,

    I have made such Custom Cervices quite a few times by now. And I got them to work with return complex data types (classes). I usually do something like this:

    technet.microsoft.com/.../gg844225.aspx

    Is that helping you?

    Or could you point out your problem more explicitly?

    BR

    Olof

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Mea_ Profile Picture

Mea_ 4

#3
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans