First We need to configure the application Registration in Azure
1-Open the Azure Portal Portal.Azure.com
2-Type the user name and password of the admin
3-Create New Registration Type any name
4-A new Application or Client ID will be created
5- Add new redirect URI(AxUrl/YorServiceGroupName)
6-Add permissions as the screen below
7-Grant Access for the admin
8-Create the Secrete Key
string aosUri = "https://usnconeboxax1aos.cloud.onebox.dynamics.com";
string activeDirectoryTenant = "https://login.windows.net/albabtaingroupkw.onmicrosoft.com";
string activeDirectoryClientAppId = "b99f1271-0da6-407a-8054-dcc452688d02";
string activeDirectoryClientAppSecret = "@yKp*b.Hxr]wQkDo1zdTICP0Xoa6L16v";
string activeDirectoryResource = "https://usnconeboxax1aos.cloud.onebox.dynamics.com";
AuthenticationContext authenticationContext = new AuthenticationContext(activeDirectoryTenant);
string aadClientAppSecret = activeDirectoryClientAppSecret;
ClientCredential creadential = new ClientCredential(activeDirectoryClientAppId, activeDirectoryClientAppSecret);
AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(activeDirectoryResource, creadential).Result;
string oAuthHeader = authenticationResult.CreateAuthorizationHeader();
string serviceName = "TestServiceGroup";
string soapServiceUriString = GetSoapServiceUriString(serviceName, aosUri);
EndpointAddress endpointAddress = new EndpointAddress(soapServiceUriString);
Binding binding = GetBinding();
//string soapServiceUriString = GetSoapServiceUriString(serviceName, aosUri);
myService.GenerateUniqueStringClient objClient = new myService.GenerateUniqueStringClient(binding, endpointAddress);
myService.CallContext callContext = new myService.CallContext { Company = "USMF" };
IClientChannel objChannel = objClient.InnerChannel;
var strOut = "";
using (OperationContextScope dimServiceOperContext = new OperationContextScope(objChannel))
{
HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
requestMessage.Headers[OAuthHelper.OAuthHeader] = oAuthHeader;
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
// IList dimensionContracts = ((myService.GenerateUniqueString)objChannel).HelloWorld(new myService.HelloWorld()).result;
strOut = ((myService.GenerateUniqueString)objChannel).HelloWorld(new myService.HelloWorld(callContext,"Hesham ")).result;
IList customers = ((myService.GenerateUniqueString)objChannel).getCustomers(new myService.getCustomers()).result;
foreach (myService.myCustTable dimensionContract in customers)
{
Console.WriteLine(dimensionContract.ParmCustName);
}
}
Console.WriteLine(strOut);
Console.Read();
1-Open the Azure Portal Portal.Azure.com
2-Type the user name and password of the admin
3-Create New Registration Type any name
4-A new Application or Client ID will be created
5- Add new redirect URI(AxUrl/YorServiceGroupName)
6-Add permissions as the screen below
7-Grant Access for the admin
8-Create the Secrete Key
string aosUri = "https://usnconeboxax1aos.cloud.onebox.dynamics.com";
string activeDirectoryTenant = "https://login.windows.net/albabtaingroupkw.onmicrosoft.com";
string activeDirectoryClientAppId = "b99f1271-0da6-407a-8054-dcc452688d02";
string activeDirectoryClientAppSecret = "@yKp*b.Hxr]wQkDo1zdTICP0Xoa6L16v";
string activeDirectoryResource = "https://usnconeboxax1aos.cloud.onebox.dynamics.com";
AuthenticationContext authenticationContext = new AuthenticationContext(activeDirectoryTenant);
string aadClientAppSecret = activeDirectoryClientAppSecret;
ClientCredential creadential = new ClientCredential(activeDirectoryClientAppId, activeDirectoryClientAppSecret);
AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(activeDirectoryResource, creadential).Result;
string oAuthHeader = authenticationResult.CreateAuthorizationHeader();
string serviceName = "TestServiceGroup";
string soapServiceUriString = GetSoapServiceUriString(serviceName, aosUri);
EndpointAddress endpointAddress = new EndpointAddress(soapServiceUriString);
Binding binding = GetBinding();
//string soapServiceUriString = GetSoapServiceUriString(serviceName, aosUri);
myService.GenerateUniqueStringClient objClient = new myService.GenerateUniqueStringClient(binding, endpointAddress);
myService.CallContext callContext = new myService.CallContext { Company = "USMF" };
IClientChannel objChannel = objClient.InnerChannel;
var strOut = "";
using (OperationContextScope dimServiceOperContext = new OperationContextScope(objChannel))
{
HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
requestMessage.Headers[OAuthHelper.OAuthHeader] = oAuthHeader;
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
// IList dimensionContracts = ((myService.GenerateUniqueString)objChannel).HelloWorld(new myService.HelloWorld()).result;
strOut = ((myService.GenerateUniqueString)objChannel).HelloWorld(new myService.HelloWorld(callContext,"Hesham ")).result;
IList customers = ((myService.GenerateUniqueString)objChannel).getCustomers(new myService.getCustomers()).result;
foreach (myService.myCustTable dimensionContract in customers)
{
Console.WriteLine(dimensionContract.ParmCustName);
}
}
Console.WriteLine(strOut);
Console.Read();
No comments:
Post a Comment