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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Consuming Inbound service

(0) ShareShare
ReportReport
Posted on by 1,552

I created the following class for service "CCService" and created a service group called "CCServiceGroup"

class CC
{
    public ContractResponse createCust(ContractRequest cust)
    {
        CustTable custTable;
        ContractResponse response = new ContractResponse();

         ttsBegin;
         custTable.AccountNum = custDetails.CustomerAccount();
         custTable.CustGroup = custDetails.CustGroup();
         custTable.insert();
         ttscommit;

        return response;
    }

}
//ContractResponse returns string success
//ContractRequest has accountNum and CustGroup parameters

I added the clientId in D365FO

I took the code for AuthenticationUtility, SoapUtility and SoapConsoleApplication from github:  https://github.com/microsoft/Dynamics-AX-Integration/tree/master/ServiceSamples

Now in the code for SoapConsoleApplication, how i'm going to call the service above?

Here's the code for SoapConsoleApplication

using AuthenticationUtility;
using SoapUtility.UserSessionServiceReference;
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;

namespace SoapConsoleApplication
{
    class Program
    {
        public const string UserSessionServiceName = "UserSessionService";

        [STAThread]
        static void Main(string[] args)
        {
            var aosUriString = ClientConfiguration.Default.UriString;

            var oauthHeader = OAuthHelper.GetAuthenticationHeader();
            var serviceUriString = SoapUtility.SoapHelper.GetSoapServiceUriString(UserSessionServiceName, aosUriString);

            var endpointAddress = new System.ServiceModel.EndpointAddress(serviceUriString);
            var binding = SoapUtility.SoapHelper.GetBinding();

            var client = new UserSessionServiceClient(binding, endpointAddress);
            var channel = client.InnerChannel;

            UserSessionInfo sessionInfo = null;

            using (OperationContextScope operationContextScope = new OperationContextScope(channel))
            {
                HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
                requestMessage.Headers[OAuthHelper.OAuthHeader] = oauthHeader;
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
                sessionInfo = ((UserSessionService)channel).GetUserSessionInfo(new GetUserSessionInfo()).result;
            }

            Console.WriteLine();
            Console.WriteLine("User ID: {0}", sessionInfo.UserId);
            Console.WriteLine("Is Admin: {0}", sessionInfo.IsSysAdmin);
            Console.ReadLine();
        }
    }
}

when i ran this code i got this error on this line: sessionInfo = ((UserSessionService)channel).GetUserSessionInfo(new GetUserSessionInfo()).result;
 The message with Action 'schemas.microsoft.com/.../GetUserSessionInfo' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

How to solve this error and how to call my service ?

I have the same question (0)
  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Junior Ax,

    • About mismatch error, you may probably refresh service reference first:

    1. Go to VS solution to SoapUtility project and find Service reference -> UserSesssionServiceReference

    2. Press right-click and open Configure service reference windows

    3. Replace in address environment URL with yours (should be in format environment_url/.../UserSessionService )and press Ok

    4. Press right-click and press "Update service reference"

    • If you want to add new service (like in your case CCServiceGroup)

    1. Go to VS solution to SoapUtility project and find Service reference

    2. Press Right-click on service reference node -> Add service reference

    3. Put address environment_url/.../CCServiceGroup

    4. Put value CCServiceGroup to namespace

    5. Adjust code from example project to use your service

  • junior AX Profile Picture
    1,552 on at

    Hi Sergie,

    1. i wanted to configure the service reference for userSession but i got this error. How to solve it?

    pastedimage1588408893114v1.png

    2. As for adding my service : CCServiceGroup, you mean to add it to the SOAPConsoleApplication not the SoapUtility. right?

    3. I renamed the namespace from SoapConsoleApplication to CCServiceGroup from the main class but it's still seeing the SoapConsoleApplication. or u want me to rename the SoapUtility namespace to CCServiceGroup? Is this mandatory for things to work?


    4. Here's the SoapConsoleApplicationCode, what to amend in it? and where to add a code to call my service, and what code should i write to be able to call the service i showed in the question?

    using AuthenticationUtility;
    using SoapConsoleApplication.ServiceReference1;
    using SoapUtility.UserSessionServiceReference;
    using System;
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    
    namespace SoapConsoleApplication
    {
        class Program
        {
            public const string UserSessionServiceName = "CCServiceGroup";
    
            [STAThread]
            static void Main(string[] args)
            {
                var aosUriString = ClientConfiguration.Default.UriString;
    
                var oauthHeader = OAuthHelper.GetAuthenticationHeader(true);
                var serviceUriString = SoapUtility.SoapHelper.GetSoapServiceUriString(UserSessionServiceName, aosUriString);
    
                var endpointAddress = new System.ServiceModel.EndpointAddress(serviceUriString);
                var binding = SoapUtility.SoapHelper.GetBinding();
    
                var client = new UserSessionServiceClient(binding, endpointAddress);
                var channel = client.InnerChannel;
    
                UserSessionInfo sessionInfo = null;
    
                using (OperationContextScope operationContextScope = new OperationContextScope(channel))
                {
                    HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
                    requestMessage.Headers[OAuthHelper.OAuthHeader] = oauthHeader;
                    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
                    sessionInfo = ((UserSessionService)channel).GetUserSessionInfo(new GetUserSessionInfo()).result;
                }
    
                Console.WriteLine();
                Console.WriteLine("User ID: {0}", sessionInfo.UserId);
                Console.WriteLine("Is Admin: {0}", sessionInfo.IsSysAdmin);
                Console.ReadLine();
            }
        }
    }
    
    

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi JuniorAx,

    1. You need to install .net 4.5.2 (www.microsoft.com/.../details.aspx

    2. If you are using demo project, it's SoapUtility project

    3. You don't need to rename any namespaces. When you add your service to the project, you can use newly generated classes in the main as well.

    4. After you successfully add a new service reference to the SoapUtility project, you need to replace some lines in the main method

    UserSessionServiceClient -> CCServiceGroupClient

    UserSessionService -> CCServiceGroup

    GetUserSessionInfo -> createCust (here you need also to create inbound contract object ContractRequest and pass it to call)

  • junior AX Profile Picture
    1,552 on at

    when i tried to install it, it said

    pastedimage1588413802819v1.png

    i can't even add my new service reference because of this error, but i can add it to SoapConsoleApp but u said the correct place is SoapUtility so how to solve it?
    pastedimage1588413843242v2.png

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi JuniorAx,

    If you can't install it, go to SoapUtility project properties and select another Target framework on Application tab (next closest to 4.5.2)

  • junior AX Profile Picture
    1,552 on at

    Hi Sergie,

    the next closest is 4.6 and i got the error again

    pastedimage1588424516408v1.png

    and it stopped seeing the reference

    pastedimage1588424570294v2.png

  • junior AX Profile Picture
    1,552 on at

    Hi Sergie,

    i removed the SoapUtility Project with 4.5.2 and add it again and the error disappeared.

    1. i replaced the url of sessionService to   MyEnvironmentURL/services/UserSessionService?wsdl  and updated service reference

    2. i added new service referenece   MyEnvironmentUrl/soap/services/CCServiceGroup

    3. Replaced UserSessionServiceClient  with  CCClient not  CCServiceGroupClient (because the name of class is CC and the name of the group is CCServiceGroup)  btw what does client here mean?

    4. Replaced UserSessionService with CC not CCServiceGroup 

    5. Replaced GetUserSessionInfo with  createCust  as u mentioned and passed ContractRequest

    here's how it looks now:

    using AuthenticationUtility;
    using SoapUtility.ServiceReference1;
    using SoapUtility.UserSessionServiceReference;
    using System;
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    
    namespace SoapConsoleApplication
    {
        class Program
        {
            public const string UserSessionServiceName = "CCServiceGroup";
    
            [STAThread]
            static void Main(string[] args)
            {
                var aosUriString = ClientConfiguration.Default.UriString;
    
                var oauthHeader = OAuthHelper.GetAuthenticationHeader(true);
                var serviceUriString = SoapUtility.SoapHelper.GetSoapServiceUriString(UserSessionServiceName, aosUriString);
    
                var endpointAddress = new System.ServiceModel.EndpointAddress(serviceUriString);
                var binding = SoapUtility.SoapHelper.GetBinding();
    
                var client = new CCClient(binding, endpointAddress);
                var channel = client.InnerChannel;
    
                CC sessionInfo = null;
    
    
                using (OperationContextScope operationContextScope = new OperationContextScope(channel))
                {
                    HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
                    requestMessage.Headers[OAuthHelper.OAuthHeader] = oauthHeader;
                    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
                    sessionInfo = ((CC)channel).createCust(new ContractRequest()).result;
                }
    
                Console.WriteLine();
                //Console.WriteLine("User ID: {0}", sessionInfo.UserId);
                //Console.WriteLine("Is Admin: {0}", sessionInfo.IsSysAdmin);
                Console.ReadLine();
            }
        }
    }

    I'm getting an error on (new ContractRequest)  : cannot convert from 'SoapUtility.ServiceReference1.ContractRequest' to 'SoapUtility.ServiceReference1.createCust' SoapConsoleApplication 

    how to solve this? and what to do next to be able to create a customer and see it on D365?

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi JuniorAx,

    Looks like there is another issue with .net version. Try to set it back to 4.5.2 and try to configure service reference UserSessionServiceReference again.

  • junior AX Profile Picture
    1,552 on at

    Hi Sergie,

    yes thanks i mentioned in my previous reply that when i put it again it worked, but can u look at my previous reply and see my questions there

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi JuniorAx,

    You pass wrong parameter for createCust method, it should be something like:

    var contract = new ContractRequest();

    // Fill contract

    ((CC)channel).createCust(new createCust(null, contract))

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans