Hi,
Following the SoapConsole application on https://github.com/microsoft/Dynamics-AX-Integration, I was able to configure and successfully get data from the UserSessionService. However, as I tried to adapt the source code to call the QueryService, it throws an UnauthorizedAccessException
Here's the sampled routine that I wrote:
static void Main(string[] args)
{
// Confirmed to work using by both debugging and successfully call UserSessionService
string token = OAuthHelper.GetAuthenticationHeaderWithSecret();
var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
var queryClient = new QueryServiceClient(binding, new EndpointAddress(OAuthHelper.soapQueryServiceEndpoint));
var channel = queryClient.InnerChannel;
DataSet dataSet;
Paging paging = null;
using (OperationContextScope operationContextScope = new OperationContextScope(channel)){
HttpRequestMessageProperty httpRequestMessage = new HttpRequestMessageProperty();
httpRequestMessage.Headers.Add(OAuthHelper.oauthHeader, token);
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestMessage;
/* Next line throws:
System.ServiceModel.FaultException
HResult=0x80131501
Message=Fault was thrown by the service for request 00000000-0000-0000-0000-000000000000. Exception details:
Type: System.UnauthorizedAccessException
Message: No security token is provided in request
Source=mscorlib
StackTrace:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at QueryServiceTest.QueryServiceRef.IQueryService.ExecuteStaticQuery(ExecuteStaticQueryRequest request)
at QueryServiceTest.Program.Main(String[] args) in C:\Users\Administrator\source\repos\QueryServiceTest\QueryServiceTest\Program.cs:line 42
*/
ExecuteStaticQueryResponse resp = ((IQueryService)channel).ExecuteStaticQuery(new ExecuteStaticQueryRequest("CusTable", paging));
dataSet = resp.ExecuteStaticQueryResult;
} /* Next do things with DataSet returned by the query ...*/
}
Can anyone tell me what I did wrong? I'm using the OneBox VM for testing