Cassia: Win32Exception no more data available - cassia

I'm using Cassia to get the sessions of two servers.
- Windows 2003 R2 Terminal Server
- Windows 2008 R2 Server
The second one, which is not a terminal server works fine. However the first one is getting some issues.
The error message is:
System.ComponentModel.Win32Exception: No more data is available
at Cassia.Impl.NativeMethodsHelper.GetSessionInfos(ITerminalServerHandle server)
at Cassia.Impl.TerminalServer.GetSessions()
at Server_Sessions.Program.Main(String[] args)
Can anyone help with this error message and what to do?
The code I found so far for testing purposes:
ITerminalServicesManager manager = new TerminalServicesManager();
using (ITerminalServer server = manager.GetRemoteServer("server"))
{
server.Open();
foreach (ITerminalServicesSession session in server.GetSessions())
{
Console.WriteLine("Session ID: " + session.SessionId);
Console.WriteLine("User: " + session.UserAccount);
}
}

After trying a few things I found my mistake. Code is tested and working. I needed to use Impersonation, because my user account is not working on the server. So I impersonate as the standard user on this server and you'll get the relevant information.
using(Impersonation.LogonUser(domain, user, password, LogonType.NewCredentials))
{
ITerminalServicesManager manager = new TerminalServicesManager();
using (ITerminalServer server = manager.GetRemoteServer(server))
{
server.Open();
foreach (ITerminalServicesSession session in server.GetSessions())
{
//Do your stuff here.
}
}
}

Related

Cannot view sauce labs test results

I have two questions here. One, I am not able to run my appium tests against the sauce labs driver url specified in my account settings https://xxxxx:xxxxxxx#ondemand.eu-central-1.saucelabs.com:443/wd/hub. I do not get any error too..
But, i am able to run my tests against http://appium.testobject.com/wd/hub url. But i am not sure where to see my test results. If i try https://app.testobject.com, I am not able to login even though i give the correct credentials and am already logged in sauce labs. Please help.
I noticed a few things that could be doing wrong here. First, you are trying to run the tests on the European datacenter and port 443, which is an https connection. See which endpoint you should connect to. Some possible solutions:
Make sure you are using the endpoint for US West (if you are in the US and that is the data center you signed up for)
All your capabilities are up to date
You used your sauce username and access key when connecting to the driver.
It's hard to know what is wrong without capabilities and knowing if you want to connect to a virtual device or a real device, testing an app or browser. Here is an example configuration for an app test on RDC:
#BeforeMethod
public void setup(Method method) throws MalformedURLException {
System.out.println("Sauce iOS Native - BeforeMethod hook");
String username = System.getenv("SAUCE_USERNAME");
String accesskey = System.getenv("SAUCE_ACCESS_KEY");
String sauceUrl;
if (region.equalsIgnoreCase("eu")) {
sauceUrl = "#ondemand.eu-central-1.saucelabs.com:443";
} else {
sauceUrl = "#ondemand.us-west-1.saucelabs.com:443";
}
String SAUCE_REMOTE_URL = "https://" + username + ":" + accesskey + sauceUrl +"/wd/hub";
String appName = "iOS.RealDevice.SauceLabs.Mobile.Sample.app.2.7.1.ipa";
String methodName = method.getName();
URL url = new URL(SAUCE_REMOTE_URL);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "iPhone 8.*");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("automationName", "XCuiTest");
capabilities.setCapability("app", "storage:filename="+appName);
try {
iosDriver.set(new IOSDriver(url, capabilities));
} catch (Exception e) {
System.out.println("*** Problem to create the iOS driver " + e.getMessage());
throw new RuntimeException(e);
}
}
I found out how to view my test results while using http://appium.testobject.com/wd/hub url. Navigate to saucelabs as usual. Then select "legacy rdc" under Sauce Apps in the displayed page. You can view the results in the displayed window.

Why won't my ASP.NET application export CSV when hosted as an Azure Web app?

MY application exports CSV's fine when I test it from Visual Studio, but when I deploy it to an Azure as a Web app, instead of exporting a CSV I get a Error code: ERR_INVALID_RESPONSE.
Below is the method I use :
public void ExportEmpReport(int? er_id)
{
var er_hdr = db.expense_report_hdr.Include(w => w.employeeExpUser).Where(x => x.ID == er_id).FirstOrDefault();
StringWriter sw = new StringWriter();
sw.WriteLine("Employee Name: " + er_hdr.employeeExpUser.fullname + ", Period: " + er_hdr.period + ", Expense Report ID: " + er_id);
sw.WriteLine("Date of Expense , Expense Class , Detail , Cust/Conv , Notes , Amount , GL Code , Project Code");
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment;filename=ExpenseReport_" + er_id + ".csv");
Response.ContentType = "text/csv";
var lines = db.expense_report_line.Where(y => y.er_id == er_id);
foreach (var line in lines)
{
string exp_class = line.expenseType.expense.ToString().Replace(",", "");
string detail = (line.expense_detail != null) ? line.expense_detail.Replace(",", "") : "";
string cust_conv = (line.cust_conv != null) ? line.cust_conv.Replace(",", "") : "";
string notes = (line.notes != null) ? line.notes.Replace(",", "") : "";
sw.WriteLine(string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", line.expense_date, exp_class, detail, cust_conv, notes, line.amount, line.gl_code.GL_code, line.project_code));
}
Response.Write(sw.ToString());
Response.End();
}
Here are some suggestions you may use to try and troubleshoot it:
A. Debug the web app locally, while connected to the DB on Azure. Are the tables being read correctly?
If the code fails to read the data from the database, make sure that the database is updated to the latest schema.
B. If it reads the data correctly, debug it step by step, and watch exactly where it fails.
If it fails at a particular line, remove/replace some lines of code until the local web app is running correctly against the DB on Azure. You may be able to identify the offending line(s) of code, and then report back here to allow others to help you troubleshoot further.
C. Once you get it working with the local app against the DB on Azure, deploy the updated project code to the Web App on Azure to see if it still runs correctly.
If it still doesn't work, maybe there's a setting on your Web App that is preventing it from running the code successfully.
D. Check the version of the .NET Framework on the Web App in Azure. The choices should be v3.5 or v4.6 (for non-Core 1.0 applications).
If it has the wrong version selected, make sure you select the correct version.
E. Enable Remote Debugging of the Web App running on Azure.
There's a Remote Debugging feature that you can toggle on/off in the Application Settings blade, where you can also select the VS version (2012, 2013, 2015). Turn it on to pinpoint which line of code it's failing at.

IIS 8.5 Win 8.1 pro localHost not working

I have researched for days and not found an answer. I have used both google and Stack and MDSN so I finally thought it is time to ask the question. I am a new developer I completed my first assignment and my computer died. I got Win 8.1 pro and IIS 8.5 and now I am tasked with making that work with SQL 2012. I have it so I can load up the localhost to the first page of the app which is a login and then when I am debuging using Visual Studio after I start to log in
the first call to the db this comes up
An exception of type 'System.ServiceModel.ProtocolException' occurred in mscorlib.dll but was not handled in user code
Additional information: The remote server returned an unexpected response: (405) Method Not Allowed.
Then I get the same message again and then it sends me to the error page.
I am an IIS newbie, but I have ensured IUSER has the correct authorization and I have checked all of the web.configs, as well as the applicationHost file. This has to be a IIS problem is what I have come up but I would gladly be wrong if someone told me I was wrong and corrected. Thanks for the help.
Code Example
The first call to db where the first error pops up
MYapp.GlobalDataService.GlobalDataServiceClient gdc = new Myapp.Proxy.GlobalDataService.GlobalDataServiceClient();
ReadLogosResult result = gdc.GetLogos(_customerId, region_id, branch_id);
if (result != null)
{
logoContent = result.Logo;
}
This is after clicking login
public static int GetUserId(IIdentity contextIdentity)
{
FormsIdentity identity = contextIdentity as FormsIdentity;
if (identity == null)
{
throw new ApplicationException("cannot cast context identity to FormsIdentity type");
}
return Convert.ToInt32(identity.Ticket.UserData.Split(';')[0]);
}
Then this
for (int i = 0; i < ContextKeys.Length; i++)
{
string ContextKey = ContextKeys[i];
if (ContextKey == "appErr")
{
obj = (Exception)HttpContext.Current.Application["appErr"];
HttpContext.Current.Application.Remove("appErr");
}
if (ContextKey == "userId")
{
user = (int)HttpContext.Current.Application["userId"];
HttpContext.Current.Application.Remove("userId");
}
}
errors out Object reference not set to an instance of an object
then goes to our customer error page
I got it figured out. I needed to install HTTPActivation in WCF.

MSMQ security blocking traffic from RPC traffic in Windows Server 2003

I've created a Message Queue in a server running Windows Server 2003 and created a client program that is able to send messages, but I can't pull them back. To send messages, I am using the following code (note that I am using transactional queue):
MessageQueueTransaction transaction = new MessageQueueTransaction();
transaction.Begin();
messageQueue.Send("Hello MSMQ!", "Title", transaction);
transaction.Commit();
transaction.Dispose();
To pull the messages I've tried this, without success:
MessageQueueTransaction transaction = new MessageQueueTransaction();
try
{
transaction.Begin();
MessageQueue queue = new MessageQueue(QUEUE_NAME);
Message msg = queue.Receive(new TimeSpan(0, 0, 5), transaction);
msg.Formatter = new XmlMessageFormatter(new Type[] { typeof(String) });
Console.WriteLine(msg.Label + " - " + msg.Body);
transaction.Commit();
}
catch (Exception e)
{
transaction.Abort();
Console.WriteLine(e.Message);
}
In the queue.Receive() call I am getting an exception. I've found a lot of similar questions about this, and I found this article with three possible solutions, but none of them worked for me. I disabled the firewall on the server, created the DWORD values in the registry, and one of the solutions provided seems to be specific for Windows Server 2008. Can anyone help me with remote calls from MSMQ in Windows Server 2003?

SharePoint 2010 Client Object Model - Kerberos/Claims Authentication

I'm trying to read a value from a list in a remote SharePoint site (different SP Web App). The web apps are set up with Claims Auth, and the client web app SP Managed account is configured with an SPN. I believe Kerberos and claims are set up correctly, but I am unable to reach the remote server, and the request causes an exception: "The remote server returned an error: (401) Unauthorized."
The exception occurs in the line ctx.ExecuteQuery(); but it does not catch the exception in the if (scope.HasException) instead, the exception is caught by the calling code (outside of the using{} block).
When I look at the traffic at the remote server using Wireshark, it doesn't look like the request is even getting to the server; it's almost as if the 401 occurs before the Kerberos ticket is exchanged for the claim.
Here's my code:
using (ClientContext ctx = new ClientContext(contextUrl))
{
CredentialCache cc = new CredentialCache();
cc.Add(new Uri(contextUrl), "Kerberos", CredentialCache.DefaultNetworkCredentials);
ctx.Credentials = cc;
ctx.AuthenticationMode = ClientAuthenticationMode.Default;
ExceptionHandlingScope scope = new ExceptionHandlingScope(ctx);
Web ctxWeb = ctx.Web;
List ctxList;
Microsoft.SharePoint.Client.ListItemCollection listItems;
using (scope.StartScope())
{
using (scope.StartTry())
{
ctxList = ctxWeb.Lists.GetByTitle("Reusable Content");
CamlQuery qry = new CamlQuery();
qry.ViewXml = string.Format(ViewQueryByField, "Title", "Text", SharedContentTitle);
listItems = ctxList.GetItems(qry);
ctx.Load(listItems, items => items.Include(
item => item["Title"],
item => item["ReusableHtml"],
item => item["ReusableText"]));
}
using (scope.StartCatch()) { }
using (scope.StartFinally()) { }
}
ctx.ExecuteQuery();
if (scope.HasException)
{
result = string.Format("Error retrieving content<!-- Error Message: {0} | {1} -->", scope.ErrorMessage, contextUrl);
}
if (listItems.Count == 1)
{
Microsoft.SharePoint.Client.ListItem contentItem = listItems[0];
if (SelectedType == SharedContentType.Html)
{
result = contentItem["ReusableHtml"].ToString();
}
else if (SelectedType == SharedContentType.Text)
{
result = contentItem["ReusableText"].ToString();
}
}
}
I realize the part with the CredentialCache shouldn't be necessary in claims, but every single example I can find is either running in a console app, or in a client side application of some kind; this code is running in the codebehind of a regular ASP.NET UserControl.
Edit: I should probably mention, the code above doesn't even work when the remote URL is the root site collection on the same web app as the calling code (which is in a site collection under /sites/)--in other words, even when the hostname is the same as the calling code.
Any suggestions of what to try next are greatly appreciated!
Mike
Is there a reason why you are not using the standard OM?
You already said this is running in a web part, which means it is in the context of application pool account. Unless you elevate permissions by switching users, it won't authenticate correctly. Maybe try that. But I would not use the client OM when you do have access to the API already.

Resources