I'm using NetSuite webservice in my WP7 project.
This is the link that I use (the newer version):
https://webservices.na1.netsuite.com/wsdl/v2012_1_0/netsuite.wsdl
This worked perfectly in my C# console application, but not in WP7.
In WP7, it logs in successfully, but when adding anything (employee, customer, timebill, ...) I get the following error:
"Your connection has timed out. Please log in again"
UPDATE:
this is my console code:
NetSuiteService service = new NetSuiteService();
service.CookieContainer = new CookieContainer();
Passport passport = new Passport();
passport.account = "TSTDRVxxxxxx";
passport.email = "hamzeh.soboh#para-solutions.com";
RecordRef role = new RecordRef();
role.internalId = "3";
passport.role = role;
passport.password = "passxxxx";
Status status = service.login(passport).status;
and the following is my WP7 code:
NetSuitePortTypeClient service = new NetSuitePortTypeClient();
// service.CookieContainer = new CookieContainer();
Passport passport = new Passport();
passport.account = "TSTDRVxxxxxx";
passport.email = "hamzeh.soboh#para-solutions.com";
RecordRef role = new RecordRef();
role.internalId = "3";
passport.role = role;
passport.password = "passxxxx";
service.loginAsync(passport);
uncommenting the second statement causes a runtime error.
Try without cookies, something like this:
// Instantiate the NetSuite web services
netSuiteService = new DataCenterAwareNetSuiteService(*yourAccountNumber*);
netSuiteService.Timeout = 1000 * 60 * 60;
var appInfo = new ApplicationInfo();
//App info from application netsuite
appInfo.applicationId = *yourApplicationId*;
// Prepare login credentials for request level login
netSuiteService.passport = new Passport()
{
email = yourEmail*,
password = *yourPassword*,
account = *yourAccountNumber*
};
netSuiteService.applicationInfo = appInfo;
Prefs = new Preferences();
netSuiteService.preferences = Prefs;
SearchPreferences = new SearchPreferences();
netSuiteService.searchPreferences = SearchPreferences;
Prefs.warningAsErrorSpecified = true;
Prefs.warningAsError = false;
SearchPreferences.bodyFieldsOnly = false;
Related
I am trying to call an Azure API (Text Analytics API) from a C# console application with a HttpRequest and I do not want to use any DLLs or await
but using the below snippet I am receiving "Bad Request". Can someone help me where it is going wrong.
public static void ProcessText()
{
string apiKey = "KEY FROM AZURE";
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
// Request headers
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", apiKey);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var requestUri = "https://eastus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment?" + queryString;
//HttpResponseMessage response;
// Request body
byte[] byteData = Encoding.UTF8.GetBytes("I really love Azure. It is the best cloud platform");
using (var content = new ByteArrayContent(byteData))
{
//content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = client.PostAsync(requestUri, content).Result;
Console.WriteLine(response);
Console.ReadLine();
}
}
string apiKey = "<<Key from Azure>>";
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
// Request headers
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", apiKey);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var requestUri = "https://**eastus**.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment?" + queryString;
//HttpResponseMessage response;
var body = new
{
documents = new[]
{
new
{
ID="1", text="I really love Azure. It is the best cloud platform"
}
}
};
string json = JsonConvert.SerializeObject(body);
byte[] byteData = Encoding.UTF8.GetBytes(json);
dynamic item = null;
using (var con = new ByteArrayContent(byteData))
{
//content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = client.PostAsync(requestUri, con).Result;
if (response.StatusCode == HttpStatusCode.OK)
{
string res = string.Empty;
using (HttpContent content = response.Content)
{
Task<string> result = content.ReadAsStringAsync();
res = result.Result;
}
JavaScriptSerializer serializer = new JavaScriptSerializer();
item = serializer.Deserialize<object>(res);
}
}
Hi All, I could able to get the API output using the above approach
I have gave appropriate permission for non admin account also user is added in "Distributed COM Users" group.
When trying to access Win32_DiskDrive or Win32_DiskDriveToDiskPartition class, I'm getting Generic Failure error. Is any extra permission is required?
Same is working, if I'm using admin account.
Other class like Win32_NetworkAdapterConfiguration giving result using non-admin account
if (!String.IsNullOrWhiteSpace(username) && !String.IsNullOrWhiteSpace(password))
{
ConnectionOptions connectionOptions = new ConnectionOptions
{
Impersonation = ImpersonationLevel.Impersonate,
Authentication = AuthenticationLevel.PacketPrivacy,
Timeout = TimeSpan.FromSeconds(60),
Username = username,
Password = password
};
var managementScope = new ManagementScope(#"\\" + assetNameOrIpAddress + #"\root\cimv2", connectionOptions);
managementScope.Connect();
managementObjectSearcher.Scope = managementScope;
}
You should add the right privileges
ConnectionOptions connOptions = new ConnectionOptions();
connOptions.Impersonation = ImpersonationLevel.Impersonate;
//Add AuthenticationLevel that suits your need
connOptions.Authentication = AuthenticationLevel.PacketPrivacy;
connOptions.EnablePrivileges = true;
ManagementScope scope =
new ManagementScope("MANAGEMNET_PATH"
, connOptions);
scope.Connect();
ObjectQuery query = new ObjectQuery(
"YOUR QUERY");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope, query);
String cognitoIdentityId = sp.getString("aws_identity", "");
String openIdToken = sp.getString("aws_token", "");
Map<String,String> logins = new HashMap<>();
logins.put("cognito-identity.amazonaws.com", openIdToken);
GetCredentialsForIdentityRequest getCredentialsRequest =
new GetCredentialsForIdentityRequest()
.withIdentityId(cognitoIdentityId)
.withLogins(logins);
AmazonCognitoIdentityClient cognitoIdentityClient = new AmazonCognitoIdentityClient();
GetCredentialsForIdentityResult getCredentialsResult = cognitoIdentityClient.getCredentialsForIdentity(getCredentialsRequest);
Credentials credentials = getCredentialsResult.getCredentials();
AWSSessionCredentials sessionCredentials = new BasicSessionCredentials(
credentials.getAccessKeyId(),
credentials.getSecretKey(),
credentials.getSessionToken()
);
The error was with the syntax
Correct code is
cognitoIdentityId = sp.getString("aws_identity", "");
String openIdToken = sp.getString("aws_token", "");
Map<String, String> logins = new HashMap<>();
logins.put("cognito-identity.amazonaws.com", openIdToken);
GetCredentialsForIdentityRequest getCredentialsRequest =
new GetCredentialsForIdentityRequest()
.withIdentityId(cognitoIdentityId)
.withLogins(logins);
AmazonCognitoIdentityClient cognitoIdentityClient = new AmazonCognitoIdentityClient(new AnonymousAWSCredentials());
GetCredentialsForIdentityResult getCredentialsResult = cognitoIdentityClient.getCredentialsForIdentity(getCredentialsRequest);
Credentials credentials = getCredentialsResult.getCredentials();
AWSSessionCredentials sessionCredentials = new BasicSessionCredentials(
credentials.getAccessKeyId(),
credentials.getSecretKey(),
credentials.getSessionToken()
);
AWS_KEY = sessionCredentials.getAWSAccessKeyId();
AWS_SECRET = sessionCredentials.getAWSSecretKey();
AWS_SESSION = sessionCredentials.getSessionToken();
I have 2 cookieAuthenticationoptions in my OWINStartup code, but only the first one is getting honored.
I cannot find any info. online on this, so will appreciate if someone can help me, if this is even possible. Here is my code:
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
// Enable clients to authenticate using cookies
var cookieOptions = new CookieAuthenticationOptions
{
AuthenticationType = "type1",
LoginPath = new PathString("/"),
SlidingExpiration = true,
Provider =
new CookieAuthenticationProvider
{
OnValidateIdentity = OnValidateIdentityAsync,
OnException = OnCookieException,
OnResponseSignIn = OnResponseSignIn,
},
};
// For auth tokens to properly work for both delve.office.com and <region>.delve.office.com
// we use a separate auth cookie per region/deployment.
if (!IsDevBox.Value)
{
cookieOptions.CookieName = AuthCookieNameWithoutSuffix + CookieHelper.GetCookieSuffix();
cookieOptions.CookieDomain = AuthCookieDomain;
}
// Enable clients to authenticate using cookies
var cookieOptions_BearerToken = new CookieAuthenticationOptions
{
AuthenticationType = "type2",
CookieName = "BearerToken",
LoginPath = new PathString("/"),
SlidingExpiration = true,
Provider =
new CookieAuthenticationProvider
{
OnValidateIdentity = OnValidateIdentityAsync_BearerToken,
OnException = OnCookieException,
OnResponseSignIn = OnResponseSignIn,
},
};
app.UseCookieAuthentication(cookieOptions);
app.UseCookieAuthentication(cookieOptions_BearerToken);
If I just use the BearerToken option, it works - but in the above case it is not getting honored. Any ideas?
Thanks so much!
Establishing session for Acumatica web services
I have a requirement where a session is to be established using web services, and then use that session to perform subsequent actions. E.g. Creating SOOrder and Shipment using web services using a previously created session/token.
SOOrder.Screen content = new SOOrder.Screen();
content.Url = InstanceUrl + “/Soap/SO301000.asmx";
content.CookieContainer = new System.Net.CookieContainer();
SOOrder.LoginResult lresult= content.Login(Username, password);
Using this, I have already obtained a session in lresult.Session.
Now, I would like to use this session in below shipmentcontent without calling login again.
SOShipment.Screen shipmentcontent = new SOShipment.Screen();
shipmentcontent.Url = InstanceUrl + "(W(3))/Soap/SO302000.asmx";
shipmentcontent.CookieContainer = new System.Net.CookieContainer();
shipmentcontent.Login(Username, password);
By package various screens in Web Services (SM.20.70.40) found under System -> Integration -> Configure -> Web Services you create a single end-point for all these screens. Consume this service end-point in you app, login only once and call out to all those screens.
thnx
If I understand you corectly you want to persist your login connection between different actions in Acumatia. In order to achieve this, I used the following approach:
Create graph:
public class Importer : PXGraph
{
}
Inside graph created following code:
public string GetHostUrl()
{
var nextIndex = HttpContext.Current.Request.Url.ToString().IndexOf("/", 7, StringComparison.Ordinal) + 1;
var urlStart = HttpContext.Current.Request.Url.ToString().IndexOf("/", nextIndex + 1, StringComparison.Ordinal);
var url = HttpContext.Current.Request.Url.ToString().Substring(0, urlStart);
return url;
}
public Screen Screen
{
get
{
var context = new Screen
{
CookieContainer = new CookieContainer(),
AllowAutoRedirect = true,
EnableDecompression = true,
Timeout = 1000000
};
var nextIndex = HttpContext.Current.Request.Url.ToString().IndexOf("/", 7, StringComparison.Ordinal) + 1;
var urlStart = HttpContext.Current.Request.Url.ToString().IndexOf("/", nextIndex + 1, StringComparison.Ordinal);
context.Url = HttpContext.Current.Request.Url.ToString().Substring(0, urlStart) + "/Soap/IMPORTET.asmx";
return context;
}
}
and then between different screens shared context of the Screen.
For example like this:
var scr = Screen;
var userName = PXAccess.GetUserName();
var password = GetUserPassword();
var context = Screen;
var lgRes = context.Login(userName, password);
but I preserved user password between different sessions