How to consume AX dynamics web service in windows phone 8.1 universal app - windows-runtime

I tried consume a AX dynamics secured web service in windows phone universal app. But i am unable to do so as windows phone run-time doesn't support service models(i.e. It doesn't provide option to add service reference). Hence Microsoft has proposed a work around using HttpClient Class.
So i did the following:
using (HttpClient client = new HttpClient())
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://xxxxx/xppservice.svc/GetData");
HttpResponseMessage response = await client.SendAsync(request);
string data = await response.Content.ReadAsStringAsync();
var dialog = new MessageDialog(data);
await dialog.ShowAsync();
}
But the problem here is, the service which i am using is secured and i have the authentication credentials. But i am unable to figure out how supply them while sending the request. Can you please help me?
A

Related

AWS .NET SDK on Linux

I am currently moving an ASP.NET application made by a third party from Windows to Linux. I read the documentation and nothing indicates this should be a problem, but sadly
var profile = new CredentialProfile(profileName, credentials) {
Region = RegionEndpoint.EUWest1
};
var netSDKFile = new NetSDKCredentialsFile();
netSDKFile.RegisterProfile(profile);
throws the following exception
Unhandled Exception: Amazon.Runtime.AmazonClientException: The encrypted store is not available. This may be due to use of a non-Windows operating system or Windows Nano Server, or the current user account may not have its profile loaded.
at Amazon.Util.Internal.SettingsManager.EnsureAvailable()
at Amazon.Runtime.CredentialManagement.NetSDKCredentialsFile..ctor()
Is the Amazon .NET SDK(or a part of it) not supported on Linux? If that is the case, is there a possible workaround?
For the most part there is very little that isn't supported on Linux that is supported on Windows. Off of the top of my head I can't think of anything besides NetSDKCredentialsFile which is due to the fact it uses Win32 API to encrypt credentials.
You can use SharedCredentialsFile to register a profile in the credentials file stored under ~/.aws/credentials. This is the same credential stored supported by all of the other AWS SDK and Tools.
Following on from Norm's answer, I found this resource that explained how to use Shared Credentials: https://medium.com/#somchat/programming-using-aws-net-sdk-9ce3f5119633
This is how I was previously using NetSDKCredentials, which won't work for Linux/Mac OS:
//Try this code on a non-Windows platform and you will see the above error
var options = new CredentialProfileOptions
{
AccessKey = "access_key",
SecretKey = "secret_key"
};
var profile = new CredentialProfile("default", options);
profile.Region = RegionEndpoint.USWest1;
NetSDKCredentialsFile file = new NetSDKCredentialsFile();
file.RegisterProfile(profile);
But I was then able to use this example to use SharedCredentials:
var credProfileStoreChain = new CredentialProfileStoreChain();
if (credProfileStoreChain.TryGetAWSCredentials("default", out AWSCredentials awsCredentials))
{
Console.WriteLine("Access Key: " + awsCredentials.GetCredentials().AccessKey);
Console.WriteLine("Secret Key: " + awsCredentials.GetCredentials().SecretKey);
}
Console.WriteLine("Hello World!");
You'll then be able to see your code is able to access the keys:
Access Key: A..................Q
Secret Key: 8.......................................p
Hello World!
I then used System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform() (as I am using this code on both Windows and Linux), to determine which credentials to use:
using System.Runtime.InteropServices;
//NETSDK Credentials only work on Windows - must use SharedCredentials on Linux
bool isLinux = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
if (isLinux) {
//Use SharedCredentials
} else {
//Use NetSDKCredentials
}
You may find this section of the AWS documentation helpful, too: https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/net-dg-config-creds.html#creds-locate

API testing using Selenium

I'm new to API testing. I need to integrate only one flow of API through Selenium as rest of GUI is already present.
I use API url on client browser, I get the result[json format]
I tried on SoapUI [REST] with the url, it gave the result[json format]
But when I try it on Selenium, I'm getting internal server error 500.
Please let me know the config changes that I need to take care.
string apiurl = "https://example.org/alfresco/s/org/alfresco/faceted/search?"
Here is the snippet of code i tried
URL url = new URL(apiurl);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
String authString = "user:Password";
byte[] bytesEncoded = Base64.encodeBase64(authString.getBytes());
String authEncoded = new String("Basic "+bytesEncoded);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
conn.setRequestProperty("Authorization", authEncoded);
conn.setRequestMethod("GET");
conn.setRequestProperty("User-Agent", "Apache-HttpClient/4.1.1 (java 1.5)");
conn.connect();
System.out.println(conn.getResponseCode());
I split the URL as
URL url = new URL(url);
conn.setRequestProperty("resource", "/alfresco/s/org/alfresco/faceted/search?");
conn.setRequestProperty("query", "%28Keywords%3A%27test%27%29");
conn.setRequestProperty("format", "json");
conn.setRequestProperty("resource", url+ "alfresco/s/org/alfresco/faceted/search?query=%28Keywords%3A%27test%27%29&count=10&format=json");
conn.setRequestProperty("Accept", "application/json");
Here I get 200 as response, but the response is on the example.org and not on the query appended.
Kindly let me know what is wrong that have done or need to add any information.
Maybe it is a little rude and not regarding current topic but I want to prevent you from doing a wrong job in future.
Using Selenium Webdriver for API testing you'll suffer a lot of pain.
Selenium Webdriver is not used for this porpuse.
Instead it there are a lot of good automation tools to test API.
One of them is Postman (chrome extension https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en)
Using this tool you'll get much more features and will be able to test any API with any requirenments.
I doubt you'll be able to do it with selenium Webdriver.

How to send parameter using body?

I am using IBM mobilefirst adapter to get data from server in my windows phone 8.1 application. when I am invoking the worklight adapter using c# code, my parameters are visible in url, however I want to send it as body. How to achieve this?
Following code I use for invoking adapter.
WLProcedureInvocationData invocationData = new WLProcedureInvocationData("CreditCardAdapter", "getAllRegisterCard", true);
//invocationData.setParameters(new Object[] { custId, version });
Object[] parameter = { custId, version };
String myContextObject = "InvokingAdapterProceduresWP8";
invocationData.setParameters(parameter);
WLRequestOptions options = new WLRequestOptions();
WLClient.getInstance().invokeProcedure(invocationData, new AllRegisterCardsInvokeListener(), options);
Your requirement cannot be achieved using MFPF 7.1 native C# Silverlight SDK.
However, this can be achieved using WLResourceRequest API that is available in MFPF 7.1 native Windows Universal SDK.For details, refer to the API documentation available here.

Create OneNote (client) Notebook with OneNote API

I can use the code below to create a page in a section and I can create a Notebook in the OneNote OneDrive using the APIGee console app, but I cannot figure out how to create a new Notebook in the OneNote client program. Below is a snippet of my code to create a page in the Foo section.
How can I modify this code to create a new Notebook in the client?
private static readonly Uri PagesEndPoint = new Uri("https://www.onenote.com/api/v1.0/pages?sectionName=Foo");
HttpResponseMessage response;
using (var imageContent = new StreamContent(await GetBinaryStream("assets\\SOAP.jpg")))
{
imageContent.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
HttpRequestMessage createMessage = new HttpRequestMessage(HttpMethod.Post, PagesEndPoint)
{
Content = new MultipartFormDataContent
{
{new StringContent(simpleHtml, System.Text.Encoding.UTF8, "text/html"), "Presentation"},{imageContent, imagePartName}
}
};
// Must send the request within the using block, or the image stream will have been disposed.
response = await client.SendAsync(createMessage);
}
tbResponse.Text = response.ToString();
return await TranslateResponse(response);
If the create notebook API call returns a success (201), it means the notebook has been created successfully on the user's OneDrive. However, the notebook will not automatically show up in the OneNote clients for the user. The user will need to open the newly created notebook in one of the OneNote client apps.
Alternatively, you can use the links.oneNoteClientUrl.href property from the API response message to open the notebook for the user in the OneNote client for them.
Hope that helps.
Thanks,
James
If you have OneNote installed, you may use the OneNote COM API. There is a VanillaAddin you can modify here: https://github.com/OneNoteDev/VanillaAddIn
In addition you can just write a Console app using the same COM API to do this (so you don't need to write a COM Add-in).

HttpClient Portable returns 404 notfound on WP8

I'm porting a W8 application that uses httpclient library to connect to our server.
The main purpose of the application is to send images, but when I try to send pictures on my WP8 I got a 404 not found error (seems that Microsoft remapped to 404 a lot of errors), if i check the server logs, I can see that the server recevied about 1/4 of the image before failling. The same function seems to works fine in my W8 application (didn't tested on 3G), and works on WP8 if I use Wifi connection. I think that the problem could be the waiting time, so I tried to add Keep-Alive headers without success.
The current code I have is:
using (HttpClient httpClient = new HttpClient())
{
httpClient.Timeout = TimeSpan.FromMinutes(10);
Stream streamW = new MemoryStream();
this.bSyncOK = await Send(streamW);
streamW.Seek(0, SeekOrigin.Begin);
HttpResponseMessage response = await httpClient.PostAsync(sUri, new StreamContent(streamW));
if (response.IsSuccessStatusCode)
{
Stream streamR = await response.Content.ReadAsStreamAsync();
this.bSyncOK = await Recv(streamR);
streamR.Dispose();
}
else
throw new HostNotFoundException();
}
The same server is used to upload pictures on other platforms like IOS and Android without problems.
I reproduced the problem using fiddler to simulate modem speeds. The problem is happening because Phone's HTTPWebRequest implementation will timeout the request whenever it exceeds around 60s. In the debugger I see them getting back ERROR_INTERNET_TIMEOUT from their native layer. The only workaround I can think of at the moment would be to send the file in smaller POSTs, assuming the server supports that.