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 ?