static void Main(string[] args) { /* When making service requets to Sandbox or Prod AX environemnts it must be ensured that TLS version is 1.2 * .NET 4.5 supports TLS 1.2 but it is not the default protocol. The below statement can set TLS version explicity. * Note that this statement may not work in .NET 4.0, 3.0 or below. * Also note that in .NET 4.6 and above TLS 1.2 is the default protocol. */ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; var request = HttpWebRequest.Create(GetUserSessionOperationPath); request.Headers[OAuthHelper.OAuthHeader] = OAuthHelper.GetAuthenticationHeader(); request.Method = "POST"; request.ContentLength = 0; using (var response = (HttpWebResponse)request.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(responseStream)) { string responseString = streamReader.ReadToEnd(); Console.WriteLine(responseString); } } } Console.ReadLine(); }
static void Main(string[] args) { Uri oDataUri = new Uri(ODataEntityPath, UriKind.Absolute); var context = new Resources(oDataUri); context.BuildingRequest += (sender, e) => { var uriBuilder = new UriBuilder(e.RequestUri); // Requires a reference to System.Web and .NET 4.6.1+ var paramValues = HttpUtility.ParseQueryString(uriBuilder.Query); if (paramValues.GetValues("cross-company") == null) { paramValues.Add("cross-company", "true"); uriBuilder.Query = paramValues.ToString(); e.RequestUri = uriBuilder.Uri; } }; context.SendingRequest2 += new EventHandler <SendingRequest2EventArgs>(delegate(object sender, SendingRequest2EventArgs e) { var authenticationHeader = OAuthHelper.GetAuthenticationHeader(useWebAppAuthentication: true); e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader); }); StreamWriter stream = File.CreateText(filePath); stream.WriteLine("Entity, TestType, Workload, Duration"); stream.Flush(); stream.Close(); Console.WriteLine("Connected To " + ClientConfiguration.Default.UriString); SalesValues values; int loopCount = 100; Stopwatch sw = new Stopwatch(); values = SalesOrderHeaderV2Tester.getRandomNonRetailCombination(); for (int i = 0; i < loopCount; i++) { SalesOrderHeaderV2Tester.updateWithCompoundEntityMinimum(context, filePath, SalesOrderTester.TestType.Repetitive, SalesOrderTester.TestWorkload.UpdateCompoundMinimum, values.DataAreaId, values.SalesId); } for (int i = 0; i < loopCount; i++) { SalesOrderHeaderV2Tester.updateWithCompoundEntityMaximum(context, filePath, SalesOrderTester.TestType.Repetitive, SalesOrderTester.TestWorkload.UpdateCompoundMaximum, values.DataAreaId, values.SalesId); } Console.WriteLine("Complete. Press enter."); Console.ReadLine(); }
static void Main(string[] args) { string GetUserSessionOperationPath = string.Format("{0}{1}", ClientConfiguration.Default.UriString.TrimEnd('/'), sessionUrl); var request = HttpWebRequest.Create(GetUserSessionOperationPath); request.Headers[OAuthHelper.OAuthHeader] = OAuthHelper.GetAuthenticationHeader(); request.Method = "POST"; request.ContentLength = 0; using (var response = (HttpWebResponse)request.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(responseStream)) { string responseString = streamReader.ReadToEnd(); Console.WriteLine(responseString); } } } Console.ReadLine(); }
public static string GetAppointment(string matricula) { var aosUriString = ClientConfiguration.Default.UriString; var oauthHeader = OAuthHelper.GetAuthenticationHeader(); var serviceUriString = SoapUtility.SoapHelper.GetSoapServiceUriString("AXZTMSAppointmentServiceGroup", aosUriString); var endpointAddress = new System.ServiceModel.EndpointAddress(serviceUriString); var binding = SoapUtility.SoapHelper.GetBinding(); var client = new AXZTMSAppointmentServiceClient(binding, endpointAddress); var channel = client.InnerChannel; CallContext callContext = new CallContext(); callContext.Company = "USMF"; callContext.Language = "es"; MatriculaDC matriculaDC = new MatriculaDC(); matriculaDC.Matricula = matricula; string appointmentId = ""; using (OperationContextScope operationContextScope = new OperationContextScope(channel)) { HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty(); requestMessage.Headers[OAuthHelper.OAuthHeader] = oauthHeader; OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage; appointmentId = ((AXZTMSAppointmentService)channel).getAppointmentIdAsync(matriculaDC).Result; } return(appointmentId); }
// GET: api/Proposal/000385 public async Task <bool> Get(int id) { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(MediaType)); var authenticationHeader = OAuthHelper.GetAuthenticationHeader(useWebAppAuthentication: true); string[] splittedToken = authenticationHeader.Split(' '); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", splittedToken[1]); string rfqUrl = RFQStatusCheck + "%27" + id.ToString("D6") + "%27"; var response = await client.GetAsync(rfqUrl); var contents = await response.Content.ReadAsStringAsync(); dynamic json = JsonConvert.DeserializeObject(contents); dynamic rfqValue = json["value"]; if (rfqValue.Count > 0) { string status = rfqValue[0]["HighestRFQStatus"]; if (status == "Sent") { return(true); } } return(false); }
public async Task <string> getAppointmentId(string matricula) { // Prepare HTTP client, including authentication HttpClient client = new HttpClient(); client.BaseAddress = new Uri(ClientConfiguration.Default.UriString); client.DefaultRequestHeaders.Add(OAuthHelper.OAuthHeader, OAuthHelper.GetAuthenticationHeader()); // Define parameters string json = "{'_contract':{'Matricula':'" + matricula + "'}}"; // Create a request HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, appointmentIdUrl); request.Content = new StringContent(json, Encoding.UTF8, "application/json"); // Run the service var result = client.SendAsync(request).Result; // Display result to console if (result.IsSuccessStatusCode) { string ret = result.Content.ReadAsStringAsync().Result; if (ret == "\"\"") { return(string.Empty); } return(result.Content.ReadAsStringAsync().Result); } else { return(result.StatusCode.ToString()); } }
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(); }
// POST: api/Proposal public async Task <string> Post(Proposal value) { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(MediaType)); var authenticationHeader = OAuthHelper.GetAuthenticationHeader(useWebAppAuthentication: true); string[] splittedToken = authenticationHeader.Split(' '); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", splittedToken[1]); PropertyInfo[] proposalInfos = value.GetType().GetProperties(); Dictionary <string, string> proposalDictionary = new Dictionary <string, string>(); foreach (PropertyInfo info in proposalInfos) { proposalDictionary.Add(info.Name, info.GetValue(value, null).ToString()); } var json = JsonConvert.SerializeObject(proposalDictionary, Formatting.Indented); var stringContent = new StringContent(json, Encoding.UTF8, MediaType); var response = await client.PostAsync(ODataEntityPath + ManageProposalActionPath, stringContent); var contents = await response.Content.ReadAsStringAsync(); return(contents); }
// GET api/Embarkasi public object Get() { string GetUserSessionOperationPath = string.Format("{0}{1}", ClientConfiguration.Default.UriString.TrimEnd('/'), sessionUrl); try { // Creates an HttpWebRequest for user session URL. HttpWebRequest aadRequest = (HttpWebRequest)WebRequest.Create(GetUserSessionOperationPath); // Change TLS version of HTTP request if the TLS version value is defined in ClientConfiguration if (!string.IsNullOrWhiteSpace(ClientConfiguration.OneBox.TLSVersion)) { aadRequest.ProtocolVersion = Version.Parse(ClientConfiguration.OneBox.TLSVersion); } string tlsRequestVersion = aadRequest.ProtocolVersion.ToString(); Console.WriteLine("The TLS protocol version for the HTTP request is {0}.", tlsRequestVersion); aadRequest.Headers[OAuthHelper.OAuthHeader] = OAuthHelper.GetAuthenticationHeader(); aadRequest.Method = "GET"; aadRequest.ContentLength = 0; // Get HttpWebResponse for the response var aadResponse = (HttpWebResponse)aadRequest.GetResponse(); string tlsResponseVersion = aadResponse.ProtocolVersion.ToString(); Console.WriteLine("The TLS protocol version of the server response is {0}.", tlsResponseVersion); if (aadResponse.StatusCode != HttpStatusCode.OK) { Console.WriteLine("Could not get response from the server."); //return; } // Get response string using (Stream responseStream = aadResponse.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(responseStream)) { string responseString = streamReader.ReadToEnd(); Console.WriteLine(string.Format("\nSuccessfully received response.\nResponse string: {0}.", responseString)); aadResponse.Close(); object parse = JsonConvert.DeserializeObject(responseString); return(parse); } } // Releases the resources of the response. } catch (Exception ex) { Console.WriteLine("Failed with the exception: {0} and stack trace: {1}.", ex.ToString(), ex.StackTrace); throw new Exception(ex.Message); } // Console.ReadLine(); }
//public static IClientChannel getBindingChannel() //{ // var authenticationHeader = OAuthHelper.GetAuthenticationHeader(); // var endpointAddress = SoapHelper.GetEndPointAddress(); // var binding = SoapHelper.GetBinding(); // var client = new HMPatientServiceClient(binding, endpointAddress); // var channel = client.InnerChannel; // //UserSessionInfo sessionInfo = null; // using (OperationContextScope operationContextScope = new OperationContextScope(channel)) // { // HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty(); // requestMessage.Headers[OAuthHelper.OAuthHeader] = authenticationHeader; // OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage; // var result = ((HMPatientService)channel).getPatientBasicDetails(new getPatientBasicDetails() { _patientRecId = "0" }).result; // } // return channel; //} public static void channelHelper() { var authenticationHeader = OAuthHelper.GetAuthenticationHeader(); HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty(); requestMessage.Headers[OAuthHelper.OAuthHeader] = authenticationHeader; OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage; }
public void JsonServiceGroup1EchoContractListTest() { EnsureServiceGroup1IsPresent(); var request = HttpWebRequest.Create(ServiceGroup1EchoContractListOperationPath); request.Headers[OAuthHelper.OAuthHeader] = OAuthHelper.GetAuthenticationHeader(); request.Method = "POST"; var inputString = "SomeString"; var inputContractList = new Contract1[] { new Contract1 { parmStringMember = inputString } , new Contract1 { parmStringMember = inputString + "*" } }; var requestContract = new ContractListRequest { input = inputContractList }; var requestContractString = JsonConvert.SerializeObject(requestContract); using (var stream = request.GetRequestStream()) { using (var writer = new StreamWriter(stream)) { writer.Write(requestContractString); } } using (var response = (HttpWebResponse)request.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(responseStream)) { string responseString = streamReader.ReadToEnd(); Contract1[] returnedContractList = JsonConvert.DeserializeObject <Contract1[]>(responseString); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.IsFalse(string.IsNullOrEmpty(responseString)); Console.WriteLine(responseString); Assert.IsNotNull(returnedContractList); Assert.AreEqual(returnedContractList.Length, inputContractList.Length); Assert.AreEqual(returnedContractList[0].parmStringMember, inputContractList[0].parmStringMember); Assert.AreEqual(returnedContractList[1].parmStringMember, inputContractList[1].parmStringMember); } } } }
public ActionResult executeMessagePost(string project, string message) { var client = this.GetClient(); var channel = client.InnerChannel; var clientConfig = ClientConfiguration.getClientConfiguration(); var context = new BisMessageHttpActionServiceReference.CallContext() { Language = clientConfig.LanguageId, Company = clientConfig.CompanyId }; var oauthHeader = OAuthHelper.GetAuthenticationHeader(clientConfig); var result = "<xml>Empty</xml>"; var content = ""; try { Response.ContentType = @"text/plain"; content = this.GetInputContent(); using (OperationContextScope operationContextScope = new OperationContextScope(channel)) { HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty(); requestMessage.Headers[OAuthHelper.OAuthHeader] = oauthHeader; OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage; result = ((BisMessageHttpActionServiceReference.BisMessageStartFromHttp)channel).executeMessage(new BisMessageHttpActionServiceReference.executeMessage(context, content, message, project)).result; } return(Content(result)); } catch (Exception ex) { result = String.Format("<xml>Error: {0}</xml>", ex.Message); return(Content(result)); } finally { if (client != null) { client.Close(); } } }
public void TLSAuthTest() { string GetUserSessionOperationPath = string.Format("{0}{1}", ClientConfiguration.Default.UriString.TrimEnd('/'), sessionUrl); // Creates an HttpWebRequest for user session URL HttpWebRequest aadRequest = (HttpWebRequest)WebRequest.Create(GetUserSessionOperationPath); // Change TLS version of HTTP request if the TLS version value is defined in ClientConfiguration if (!string.IsNullOrWhiteSpace(ClientConfiguration.OneBox.TLSVersion)) { aadRequest.ProtocolVersion = Version.Parse(ClientConfiguration.OneBox.TLSVersion); } string tlsRequestVersion = aadRequest.ProtocolVersion.ToString(); Console.WriteLine("The TLS protocol version for the HTTP request is {0}.", tlsRequestVersion); aadRequest.Headers[OAuthHelper.OAuthHeader] = OAuthHelper.GetAuthenticationHeader(); aadRequest.Method = "POST"; aadRequest.ContentLength = 0; // Get HttpWebResponse for the response var aadResponse = (HttpWebResponse)aadRequest.GetResponse(); string tlsResponseVersion = aadResponse.ProtocolVersion.ToString(); Console.WriteLine("The TLS protocol version of the server response is {0}.", tlsResponseVersion); Assert.IsTrue(aadResponse.StatusCode == HttpStatusCode.OK); // Get response string using (Stream responseStream = aadResponse.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(responseStream)) { string responseString = streamReader.ReadToEnd(); Assert.IsFalse(string.IsNullOrEmpty(responseString)); Console.WriteLine(string.Format("Request sent using version {0}. Successfully received response with version {1}.", tlsRequestVersion, tlsResponseVersion)); Console.WriteLine(string.Format("\nResponse string: {0}.", responseString)); } } // Releases the resources of the response. aadResponse.Close(); }
public static Resources CreateErpContext() { Queries365.SetFakeSslCertificate(); // Resource string ODataEntityPath = ClientConfiguration.Default.UriString + "data"; Uri oDataUri = new Uri(ODataEntityPath, UriKind.Absolute); Resources context = new Resources(oDataUri); context.SendingRequest2 += new EventHandler <SendingRequest2EventArgs>(delegate(object sender, SendingRequest2EventArgs e) { var authenticationHeader = OAuthHelper.GetAuthenticationHeader(useWebAppAuthentication: true); e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader); }); return(context); }
static void Main(string[] args) { /* When making service requets to Sandbox or Prod AX environemnts it must be ensured that TLS version is 1.2 * .NET 4.5 supports TLS 1.2 but it is not the default protocol. The below statement can set TLS version explicity. * Note that this statement may not work in .NET 4.0, 3.0 or below. * Also note that in .NET 4.6 and above TLS 1.2 is the default protocol. */ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // To test custom entities, regenerate "ODataClient.tt" file. // https://blogs.msdn.microsoft.com/odatateam/2014/03/11/tutorial-sample-how-to-use-odata-client-code-generator-to-generate-client-side-proxy-class/ Uri oDataUri = new Uri(ODataEntityPath, UriKind.Absolute); var context = new Resources(oDataUri); context.SendingRequest2 += new EventHandler <SendingRequest2EventArgs>(delegate(object sender, SendingRequest2EventArgs e) { var authenticationHeader = OAuthHelper.GetAuthenticationHeader(useWebAppAuthentication: true); e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader); }); // Uncomment below to run specific examples // 1. Simple query examples QueryExamples.ReadLegalEntities(context); // QueryExamples.GetInlineQueryCount(context); // QueryExamples.GetTopRecords(context); // QueryExamples.FilterSyntax(context); // QueryExamples.FilterLinqSyntax(context); // QueryExamples.SortSyntax(context); // QueryExamples.FilterByCompany(context); // QueryExamples.ExpandNavigationalProperty(context); // 2. Simple CRUD examples // SimpleCRUDExamples.SimpleCRUD(context); // 2. Changeset examples // ODataChangesetsExample.CreateSalesOrderInSingleChangeset(context); // ODataChangesetsExample.CreateSalesOrderWithoutChangeset(context); Console.ReadLine(); }
static void Main(string[] args) { Uri oDataUri = new Uri(ODataEntityPath, UriKind.Absolute); var context = new Resources(oDataUri); context.SendingRequest2 += new EventHandler <SendingRequest2EventArgs>(delegate(object sender, SendingRequest2EventArgs e) { var authenticationHeader = OAuthHelper.GetAuthenticationHeader(); e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader); }); ReadLegalEntities(context); CreateSalesOrderSuccess(context); CreateSalesOrderFailureWithRollBack(context); CreateSalesOrderFailureWithNoRollBack(context); Console.ReadLine(); }
static void Main(string[] args) { Uri oDataUri = new Uri(ODataEntityPath, UriKind.Absolute); var context = new Resources(oDataUri); context.SendingRequest2 += new EventHandler <SendingRequest2EventArgs>(delegate(object sender, SendingRequest2EventArgs e) { var authenticationHeader = OAuthHelper.GetAuthenticationHeader(); e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader); }); Console.WriteLine(); foreach (var legalEntity in context.LegalEntities.AsEnumerable()) { Console.WriteLine("Name: {0}", legalEntity.Name); } Console.ReadLine(); }
public void EnsureServiceGroup1IsPresent() { var getRequest = HttpWebRequest.Create(ServiceGroup1ServicePath); getRequest.Headers[OAuthHelper.OAuthHeader] = OAuthHelper.GetAuthenticationHeader(); getRequest.Method = "GET"; try { using (var getResponse = (HttpWebResponse)getRequest.GetResponse()) { Assert.AreEqual(getResponse.StatusCode, HttpStatusCode.OK); } } catch { Assert.Inconclusive("ServiceGroup1 and its operations are not currently present under /api/services/ServiceGroup1/Service1/<operation_name>. You can enable the test service group by importing the included project (ServiceContractProject.axpp) and compiling the artifacts."); } }
public void JsonWeaklyTypedServiceGroup1EchoStringTest() { EnsureServiceGroup1IsPresent(); var request = HttpWebRequest.Create(ServiceGroup1EchoStringOperationPath); request.Headers[OAuthHelper.OAuthHeader] = OAuthHelper.GetAuthenticationHeader(); request.Method = "POST"; var inputString = "SomeString"; var requestContract = new { input = inputString }; var requestContractString = JsonConvert.SerializeObject(requestContract); using (var stream = request.GetRequestStream()) { using (var writer = new StreamWriter(stream)) { writer.Write(requestContractString); } } using (var response = (HttpWebResponse)request.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(responseStream)) { string responseString = streamReader.ReadToEnd(); JToken jsonObject = JToken.Parse(responseString); string returnedString = jsonObject.Value <string>(); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.IsFalse(string.IsNullOrEmpty(responseString)); Console.WriteLine(responseString); Assert.IsNotNull(returnedString); Assert.AreEqual(inputString, returnedString); } } } }
static void Main(string[] args) { // To test custom entities, regenerate "ODataClient.tt" file. // https://blogs.msdn.microsoft.com/odatateam/2014/03/11/tutorial-sample-how-to-use-odata-client-code-generator-to-generate-client-side-proxy-class/ Uri oDataUri = new Uri(ODataEntityPath, UriKind.Absolute); var context = new Resources(oDataUri); context.SendingRequest2 += new EventHandler <SendingRequest2EventArgs>(delegate(object sender, SendingRequest2EventArgs e) { var authenticationHeader = OAuthHelper.GetAuthenticationHeader(useWebAppAuthentication: true); e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader); }); // Uncomment below to run specific examples // 1. Simple query examples QueryExamples.ReadLegalEntities(context); // QueryExamples.GetInlineQueryCount(context); // QueryExamples.GetTopRecords(context); // QueryExamples.FilterSyntax(context); // QueryExamples.FilterLinqSyntax(context); // QueryExamples.SortSyntax(context); // QueryExamples.FilterByCompany(context); // QueryExamples.ExpandNavigationalProperty(context); // 2. Simple CRUD examples // SimpleCRUDExamples.SimpleCRUD(context); // 2. Changeset examples //Calling ODataChangesetsExample.CreateSalesOrderInSingleChangeset(context); ODataChangesetsExample.GetDataBase(context); ODataChangesetsExample.InsertIntoDataBase(context); //ODataChangesetsExample.CreateSalesOrderWithoutChangeset(context); Console.ReadLine(); }
public void JsonWeaklyTypedContractTest() { var request = HttpWebRequest.Create(ApplyTimeZoneOperationPath); request.Headers[OAuthHelper.OAuthHeader] = OAuthHelper.GetAuthenticationHeader(); request.Method = "POST"; DateTime inputDateTime = DateTime.Now; var requestContract = new { dateTime = inputDateTime, timeZoneOffset = 3 }; var requestContractString = JsonConvert.SerializeObject(requestContract); using (var stream = request.GetRequestStream()) { using (var writer = new StreamWriter(stream)) { writer.Write(requestContractString); } } using (var response = (HttpWebResponse)request.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(responseStream)) { string responseString = streamReader.ReadToEnd(); JToken jsonObject = JToken.Parse(responseString); DateTime appliedTimeZone = jsonObject.Value <DateTime>(); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.IsFalse(string.IsNullOrEmpty(responseString)); Console.WriteLine(responseString); Assert.IsNotNull(appliedTimeZone); Assert.AreNotEqual(appliedTimeZone.Hour, inputDateTime.Hour); } } } }
static void Func2() { Uri oDataUri = new Uri(ODataEntityPath, UriKind.Absolute); var context = new Resources(oDataUri); context.SendingRequest2 += new EventHandler <SendingRequest2EventArgs>( delegate(object sender, SendingRequest2EventArgs e) { var authenticationHeader = OAuthHelper.GetAuthenticationHeader(); e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader); }); // CreateMyCar(context); //QueryExamples.GetTopRecords(context); //QueryExamples.FilterLinqSyntax(context); //QueryExamples.CreateJournal(context); // QueryExamples.GetCustomerTopRecords(context); //QueryExamples.CreateCustomer2(context); QueryExamples.UpdateCustomer(context); //QueryExamples.ReadLegalEntities(context); Console.ReadLine(); }
public void ODataAuthTest() { var authenticationHeader = OAuthHelper.GetAuthenticationHeader(); var request = HttpWebRequest.Create(ODataEntityPath); request.Headers[OAuthHelper.OAuthHeader] = authenticationHeader; using (var response = (HttpWebResponse)request.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(responseStream)) { string responseString = streamReader.ReadToEnd(); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.IsFalse(string.IsNullOrEmpty(responseString)); } } } }
public void JsonAuthTest() { var request = HttpWebRequest.Create(GetUserSessionOperationPath); request.Headers[OAuthHelper.OAuthHeader] = OAuthHelper.GetAuthenticationHeader(); request.Method = "POST"; request.ContentLength = 0; using (var response = (HttpWebResponse)request.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(responseStream)) { string responseString = streamReader.ReadToEnd(); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.IsFalse(string.IsNullOrEmpty(responseString)); Console.WriteLine(responseString); } } } }
static void Main(string[] args) { var request = HttpWebRequest.Create(GetUserSessionOperationPath); request.Headers[OAuthHelper.OAuthHeader] = OAuthHelper.GetAuthenticationHeader(); request.Method = "POST"; request.ContentLength = 0; using (var response = (HttpWebResponse)request.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(responseStream)) { string responseString = streamReader.ReadToEnd(); Console.WriteLine(responseString); } } } Console.ReadLine(); }
static void CallChildThread(Resources context, ref Logger logger, int threadCount) { string x = ""; SalesValues values; int loopCount = 100; List <String> logs = new List <string>(); int threadId = Thread.CurrentThread.ManagedThreadId; context.BuildingRequest += (sender, e) => { var uriBuilder = new UriBuilder(e.RequestUri); // Requires a reference to System.Web and .NET 4.6.1+ var paramValues = HttpUtility.ParseQueryString(uriBuilder.Query); if (paramValues.GetValues("cross-company") == null) { paramValues.Add("cross-company", "true"); uriBuilder.Query = paramValues.ToString(); e.RequestUri = uriBuilder.Uri; } }; context.SendingRequest2 += new EventHandler <SendingRequest2EventArgs>(delegate(object sender, SendingRequest2EventArgs e) { var authenticationHeader = OAuthHelper.GetAuthenticationHeader(useWebAppAuthentication: true); e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader); }); for (int i = 0; i < loopCount; i++) { values = SalesOrderHeaderV2Tester.getRandomCombination(); logs.Add(SalesOrderHeaderV2Tester.runOneReadThread(context, threadCount, filePath, SalesOrderTester.TestType.Random, SalesOrderTester.TestWorkload.ReadThread, values.SalesId, values.DataAreaId)); } logger.addList(logs); }
static void Main(string[] args) { /* When making service requets to Sandbox or Prod AX environemnts it must be ensured that TLS version is 1.2 * .NET 4.5 supports TLS 1.2 but it is not the default protocol. The below statement can set TLS version explicity. * Note that this statement may not work in .NET 4.0, 3.0 or below. * Also note that in .NET 4.6 and above TLS 1.2 is the default protocol. */ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 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(); }
public void BasicSoapAuthTest() { var authenticationHeader = OAuthHelper.GetAuthenticationHeader(); var serviceUriString = SoapHelper.GetSoapServiceUriString(UserSessionServiceName, ClientConfiguration.Default.UriString); var endpointAddress = new System.ServiceModel.EndpointAddress(serviceUriString); var binding = 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] = authenticationHeader; OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage; sessionInfo = ((UserSessionService)channel).GetUserSessionInfo(new GetUserSessionInfo()).result; } Assert.IsNotNull(sessionInfo); Assert.IsNotNull(sessionInfo.UserId); }
static void Main(string[] args) { Uri oDataUri = new Uri(ODataEntityPath, UriKind.Absolute); var context = new Resources(oDataUri); context.SendingRequest2 += new EventHandler <SendingRequest2EventArgs>(delegate(object sender, SendingRequest2EventArgs e) { var authenticationHeader = OAuthHelper.GetAuthenticationHeader(useWebAppAuthentication: true); e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader); }); // Uncomment below to run specific examples // 1. Simple query examples QueryExamples.ReadLegalEntities(context); // QueryExamples.GetInlineQueryCount(context); // QueryExamples.GetTopRecords(context); // QueryExamples.FilterSyntax(context); // QueryExamples.FilterLinqSyntax(context); // QueryExamples.SortSyntax(context); // QueryExamples.FilterByCompany(context); // QueryExamples.ExpandNavigationalProperty(context); // 2. Simple CRUD examples // SimpleCRUDExamples.SimpleCRUD(context); // 2. Changeset examples // ODataChangesetsExample.CreateSalesOrderInSingleChangeset(context); // ODataChangesetsExample.CreateSalesOrderWithoutChangeset(context); Console.ReadLine(); }
static void Main(string[] args) { Uri oDataUri = new Uri(ODataEntityPath, UriKind.Absolute); var context = new Resources(oDataUri); context.BuildingRequest += (sender, e) => { var uriBuilder = new UriBuilder(e.RequestUri); // Requires a reference to System.Web and .NET 4.6.1+ var paramValues = HttpUtility.ParseQueryString(uriBuilder.Query); if (paramValues.GetValues("cross-company") == null) { paramValues.Add("cross-company", "true"); uriBuilder.Query = paramValues.ToString(); e.RequestUri = uriBuilder.Uri; } }; context.SendingRequest2 += new EventHandler <SendingRequest2EventArgs>(delegate(object sender, SendingRequest2EventArgs e) { var authenticationHeader = OAuthHelper.GetAuthenticationHeader(useWebAppAuthentication: true); e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader); }); SalesValues values; StreamWriter stream = File.CreateText(filePath); stream.WriteLine("Entity, TestType, Workload, Duration"); stream.Flush(); stream.Close(); Console.WriteLine("Connected To " + ClientConfiguration.Default.UriString); Stopwatch sw = new Stopwatch(); context.SalesOrderHeadersV2.FirstOrDefault(); context.SalesOrderLines.FirstOrDefault(); context.SalesOrderHeadersV2EntityOnlySalesTablePostLoad.FirstOrDefault(); context.SalesOrderHeadersV2EntityOnlySalesTablePostLoadExtended.FirstOrDefault(); //SalesOrderLineV2Tester.runGetAllPagesSkipTake(context, filePath, SalesOrderTester.TestType.Random, SalesOrderTester.TestWorkload.ReadAllPagesSkipTake); //SalesOrderLineV2Tester.runGetAllPages(context, filePath, SalesOrderTester.TestType.Random, SalesOrderTester.TestWorkload.ReadAllPagesQuery); /* * for (int i = 0; i < 100; i++) * { * values = SalesOrderHeaderV2EntityOnlySalesTableTester.getRandomCombination(); * SalesOrderHeaderV2EntityOnlySalesTableTester.runOneRead(context, filePath, SalesOrderTester.TestType.Random, SalesOrderTester.TestWorkload.Read, values.SalesId, values.DataAreaId); * } */ for (int i = 0; i < 100; i++) { values = SalesOrderHeaderV2EntityOnlySalesTablePostLoadTester.getRandomCombination(); SalesOrderHeaderV2EntityOnlySalesTablePostLoadTester.runOneRead(context, filePath, SalesOrderTester.TestType.Random, SalesOrderTester.TestWorkload.ReadPostLoad, values.SalesId, values.DataAreaId); } for (int i = 0; i < 100; i++) { values = SalesOrderHeaderV2EntityOnlySalesTablePostLoadExtendedTester.getRandomCombination(); SalesOrderHeaderV2EntityOnlySalesTablePostLoadExtendedTester.runOneRead(context, filePath, SalesOrderTester.TestType.Random, SalesOrderTester.TestWorkload.ReadPostLoadExtended, values.SalesId, values.DataAreaId); } Console.WriteLine("Complete. Press enter."); Console.ReadLine(); }