В качестве образца использования веб-сервиса можно взять файл
https://github.com/microsoft/Dynamic...ion/Program.cs, однако в конечном счете все нужно будет собрать в один проект на C#, поэтому начинаем с того, что создаем проект на C# типа Console Application. Мы можем создать проект любого типа - главное, чтобы он мог бы быть напрямую запущен пользователем.

В созданном проекте для авторизации по токену будет не хватать ссылки на библиотеку Microsoft.IdentityModel.Clients.ActiveDirectory (см узел References)

Поэтому эту библиотеку нужно добавить путем выполнения команды в Visual Studio: Tools - NuGet Package Manager - Package Manager Console
Цитата:
Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory
Выполнять команду в консоли стоит, щелкнув предварительно на Solution, а не на Project
Теперь в проект нужно добавить из заготовок от Microsoft следующие файлы:
ClientConfiguration.cs (с правками по параметрам авторизации)
OAuthHelper.cs (без правок)
SoapHelper.cs (без правок)
Также добавляем Service Reference

указав путь к веб-сервису (и нажав кнопку Go), а также указав имя Tutorial_CustServiceReference, под которым веб-сервис будет представлен в коде
Далее пишем вот такой вот класс Program.cs. Обращаю внимание, что parm-методы воспринимаются на C#, как свойства (property) класса, а перечень карточек клиента - как массив.
X++:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using AuthenticationUtility;
using SoapUtility;
using System.ServiceModel;
using System.ServiceModel.Channels;
namespace Tutorial_ConsumeServiceSOAP
{
class Program
{
public const string serviceGroupName = "Tutorial_CustServiceGroup";
public const string serviceName = "Tutorial_LabCustService";
static void Main(string[] args)
{
var aosUriString = ClientConfiguration.Default.ActiveDirectoryResource;
string bearerKey;
bearerKey = OAuthHelper.GetAuthenticationHeader(true);
var serviceUriString = SoapUtility.SoapHelper.GetSoapServiceUriString(serviceGroupName, aosUriString);
EndpointAddress endpointAddress = new System.ServiceModel.EndpointAddress(serviceUriString);
var binding = SoapUtility.SoapHelper.GetBinding();
var client = new Tutorial_CustServiceReference.Tutorial_LabCustServiceClient(binding, endpointAddress);
var channel = client.InnerChannel;
Tutorial_CustServiceReference.CallContext refContext = new Tutorial_CustServiceReference.CallContext();
refContext.Company = "RUMF";
refContext.Language = "ru";
refContext.PartitionKey = "initial";
using (OperationContextScope operationContextScope = new OperationContextScope(channel))
{
HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
requestMessage.Headers[OAuthHelper.OAuthHeader] = bearerKey;
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
Tutorial_CustServiceReference.Tutorial_CustServiceContract result;
Tutorial_CustServiceReference.Tutorial_CustServiceContract[] colResult;
result = ((Tutorial_CustServiceReference.Tutorial_LabCustService)channel).getCustDetail(new Tutorial_CustServiceReference.getCustDetail(refContext, "RUMF-000001")).result;
Console.WriteLine(string.Format("{0} | {1} | {2}", result.parmCustAccount, result.parmCustAccountName, result.parmCustGroupId));
colResult = ((Tutorial_CustServiceReference.Tutorial_LabCustService)channel).getCustListOfGroup(new Tutorial_CustServiceReference.getCustListOfGroup(refContext, "Орг")).result;
foreach (Tutorial_CustServiceReference.Tutorial_CustServiceContract iterator in colResult)
{
Console.WriteLine(string.Format("{0} | {1} | {2}", iterator.parmCustAccount, iterator.parmCustAccountName, iterator.parmCustGroupId));
}
}
Console.ReadLine();
}
}
}
Все билдим, запускаем, проверяем. Само собой, база данных должна содержать те данные, которые мы хотим получить.
У меня (на моей базе) получается такой результат: