Cannot navigate to my end point URL on ASP.NET Web App - c#

I'm trying to re-install a legacy ASP.NET Web application. It is old code and I realize that I need to redo it using ASP.NET Core. My machine was automatically rebuilt by Microsoft's December update and I lost all my programs. I'm having trouble re-installing a legacy REST Server. The clients are iPhone Apps, and I don't want to redo them now.
My machine environment is now:
Windows 10 Enterprise
Version: 1903
Installed on: 12/11/2019
OS build: 18362.535
Visual Studio 2019 Version 16.4.2
My end point URL should be: "http://www.cypresspoint.com/TrinREST/TrinService/GetData".
but it no longer works. I am getting a 404 response in my Chrome browser. The screen shows:
My complete server code is:
using System;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
[WebService(Namespace = "http://cypresspoint.com/TrinREST/TrinService")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class TrinService : WebService {
[OperationContract]
[WebGet(UriTemplate = "GetData")]
[WebMethod]
public string GetData() {
try {
var nyseTrin = 0.00M;
var msg = string.Format("{0}", nyseTrin);
return msg;
} catch (Exception ex) {
return "GetTrinData Error: " + ex.Message;
}
}
}
I then re-loaded the project as Administrator and did a Publish. The browser appeared with:
and when I click on Invoke, I get:
So far so good. However, when I try my original end point URL:
"http://www.cypresspoint.com/TrinREST/TrinService/GetData"
I still get error 404.0.
Max, I appreciate you sticking with me.
Charles

As you can see the Invoke button trigger a POST request instead of a GET request, consequently you CANNOT use the browser to test the method.
I made the connection using Postman sending a POST request
Same result if I add the service reference on a Visual Studio project
If you want

Related

System.Windows.Forms - RemoteWebDriver -> Access is denied

We have a problem with my team for several weeks.
We currently have a test in MSTest v1 and Selenium 3.11 that is dedicated to upload a photo when filling out a profile.
In local works perfectly (hehehe), but in remote (RemoteWebdriver) the server of Build & Releases (VSTS) throws an error just in the step where I interact with this window, of the Access Denied type.
It is not really Selenium who acts there, but the System.Windows.Forms library and the SendWait method of the SendKeys class that gives the error when it is launched remotely.
Screenshot of the element in question >>> UploadFile
Example code:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Windows.Forms;
using OpenQA.Selenium;
using System.IO;
//...
public class EditarFotoUsuarioAdministrador
{
public static void Execute(IWebDriver driver, string foto)
{
driver.FindElement(By.XPath("//button[#id='upload']")).Click();
System.Threading.Thread.Sleep(2000);
SendKeys.SendWait(Directory.GetCurrentDirectory() + foto);
SendKeys.SendWait(#"{Enter}");
System.Threading.Thread.Sleep(2000);
driver.FindElement(By.XPath("//button[#id='save']")).Click();
System.Threading.Thread.Sleep(500);
}
}
As I said, this in local works perfectly, but when it runs on the remote server, the whole test goes well until it reaches the SendKeys line:
AccessIsDenied
Hopefully someone has an answer, thank you very much !!
The agent need to be running as interactive mode.
I've fixed it using AutoIT3.
Loading the nuget and using its methods to send the path of the file, you can perfectly interact with any pop-up browser window.
And best of all, the remote server does it too.
Thank you very much to all !
AutoIT3 or AutoItX.Dotnet ?
can you please send the code snippet. i used below code
` AutoItX.WinActivate("Open");
AutoItX.ControlGetFocus("Open");
AutoItX.Send(file);
System.Threading.Thread.Sleep(2000);
AutoItX.ControlClick("Open", " ", "Button1");`
It works fine in local but not in remote

How to restart Cordova WP8 app?

I have a WP8 Cordova app that has one page locally and then it redirects to a server for further functionality. Both pages have the cordova JS API's available and things work well.
Except that when I want to go to the local start page again. Any anchors to it (pointing to x-wmapp0:www/index.html) do not work on the HTML side.
In addition, any tricks with plugins and invocations of CordovaBrowser.Navigate() result in UnauthorizedAccessException errors.
The fallback has been for me to try to go back in browser history like this:
window.history.go(-window.history.length + 1);
But this doesn't do anything if I spend any time in the remote pages at all. So this isn't applicable either!
Is there a decent way to get to the starting page? With help from C# or otherwise?
So the UnauthorizedAccessException stuff came from thread issues. (The VS Express for WP can sometimes hide the details of an exception pretty well.)
This is a complete plugin that performs the redirection with neatest elegance available.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using WPCordovaClassLib.Cordova;
using WPCordovaClassLib.Cordova.Commands;
namespace Cordova.Extension.Commands
{
public class Jumper : BaseCommand
{
/** Instruct the browser component to go to beginning. */
public void goHome(string unused)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
var webview = WebViewHandler.getInstance().webView;
webview.CordovaBrowser.Navigate(webview.StartPageUri);
});
}
}
}
The WebViewHandler is a singleton for sharing the Cordova WebView to plugins, described in another SO answer (thanks #MikeBryant!).

WCF Data Service 5.6 quick start

I have been trying to get a WCF Data Service server working for a few days now.
I finally backed off today and just tried to do exactly what the quick-start shows.. nothing else.. and in completely fresh project. Surely that would work.
But it didn't.. it failed the same way as my other tests.
I am just following along with this example. Using Visual Studio 2013 for Web express and the hosting is using IIS Express.
I have installed the WCF Tools version 5.6 such that Visual Studio has the WFC Data Service 5.6 template.
The gist of it is
create an ASP.Net Application Select MVC type, adding no folders for anything other than MVC and no unit tests, individual account authenticaion.
Add an ADO.Net Entity Data Model for the NorthWind database, called NorthwindEntities in web.config, importing all tables.
Add WCF Data Service 5.6 item, call it NorthWind.svc.
Change the NorthWind.svc.cs backing code to the following.
using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
namespace StackOverflowApp
{
public class NorthWindService : DataService<NorthwindEntities>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
config.UseVerboseErrors = true;
config.SetEntitySetAccessRule("Orders", EntitySetRights.AllRead | EntitySetRights.WriteMerge | EntitySetRights.WriteReplace );
config.SetEntitySetAccessRule("Order_Details", EntitySetRights.AllRead| EntitySetRights.AllWrite);
config.SetEntitySetAccessRule("Customers", EntitySetRights.AllRead);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
}
}
}
Now it is ready to build and run.. it should work.. yes?
I run it, and navigate to the service.. I am greeted with the following complaint.
<div id="content">
<p class="heading1">Request Error</p>
<p>The server encountered an error processing the request. See server logs for more details.</p>
</div>
How am I to debug that?
This is not the typical response when navigating to a page which generates an error in the application or to a page that does not exist. I get the feeling that the data.service system is generating this response.. that it actually started to process the request.. but failed for some obtuse reason.
I followed the instructions to a tee I thought, but apparently I missed something.
I've been through the process step by step several times now to try to find what I might have skipped to no avail.
Update:
Aha.. under another similar question, they recommended adding verbose messages using config.UserVerboseErrors = true. This didn't make any difference to me.. but the alternative method of using attributes sure did! Decorating the class with [ServiceBehavior(IncludeExceptionDetailInFaults = true)], now yields this more descriptive error.
The server encountered an error processing the request. The exception
message is 'Expression of type
'System.Data.Entity.Core.Objects.ObjectContext' cannot be used for
return type 'System.Data.Objects.ObjectContext''. See server logs for
more details. The exception stack trace is: blahblah
It sounds like you're using Entity Framework 6 which hasn't been out for all that long. You need to perform some additional steps to get WCF Data Services 5.6 and EF 6 to behave together nicely.
You need to add the additional WCF Data Services Entity Framework Provider Nuget package and then instead of inheriting your service from DataService<T>, you inherit from EntityFrameworkDataService<T>.
Full steps are on the data services blog here: http://blogs.msdn.com/b/astoriateam/archive/2013/10/02/using-wcf-data-services-5-6-0-with-entity-framework-6.aspx
Yes Thanks. Your answer is correct Chris. I was able to find the problem at last after I enabled the decorated version of verbose messaging, and got that extra detail regarding linking to objects being the problem.
So I found the problem and fixed it, or at least I can make it work using the quick-start guide now. Working with my own database is a little squirley still.. returns an empty set when I know I have items in the database.. but at least I now have working exhibit-A to compare against to find the issue. (Aha! found the problem there also, I had forgotten to add the entitie connection to web.config for my non-northwind database -- so its all workin' now!)
Anyway, the first decent clue was following the error message (that wasn't shown until after I enabled verbose messaging with the class attribute), found this note about the problem actually being with WCF's interface with EntityFramework 6. (had I not upgraded to version 6 I likely would not have had the problem)
https://entityframework.codeplex.com/workitem/896
Then, I searched for issues with WCF 5.6 and EntityFramework6. and whalla.. there is an alpha version of WCF which addresses the issue.
Note that if you follow the instructions here verbatim, there is still a problem (or was for me). Get alpha2 instead of alpha1 as it fixes a linking error. i.e.
Install-Package Microsoft.OData.EntityFrameworkProvider -Version 1.0.0-alpha2 -Pre
http://blogs.msdn.com/b/astoriateam/archive/2013/10/02/using-wcf-data-services-5-6-0-with-entity-framework-6.aspx
To install alpha2 today 6/7/2014 "Install-Package Microsoft.OData.EntityFrameworkProvider -Pre". Also the Microsoft.Data.Services version must be 5.6.0.0.

HTTPWebRequest.GetResponse() throws connection failure exception

I'm trying to create a simple application that does a HTTP
request/response on a button click. Here's the entire code which I got
from a reference book:
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
namespace emulator2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void button1_Click(object sender, EventArgs e)
{
Uri l_Uri = new Uri("http://www.testing.com");
HttpWebRequest l_WebReq = (HttpWebRequest)WebRequest.Create(l_Uri);
HttpWebResponse l_WebResponse =
(HttpWebResponse)l_WebReq.GetResponse();
Stream l_responseStream = l_WebResponse.GetResponseStream();
StreamReader l_SReader = new StreamReader(l_responseStream);
string resultstring = l_SReader.ReadToEnd();
Console.WriteLine(resultstring);
}
}
}
The thing that puzzles me is that when I shift the entire chunk of code
to a Windows Application, it works fine. But when I use it on a Device
Application, it just throws me an error. Here are the details of the
error:
System.Net.WebException was unhandled Message="Could not establish
connection to network." StackTrace: at
System.Net.HttpWebRequest.finishGetResponse() at
System.Net.HttpWebRequest.GetResponse() at
emulator2.Form1.button1_Click() at
System.Windows.Forms.Control.OnClick() at
System.Windows.Forms.Button.OnClick() at
System.Windows.Forms.ButtonBase.WnProc() at
System.Windows.Forms.Control._InternalWnProc() at
Microsoft.AGL.Forms.EVL.EnterMainLoop() at
System.Windows.Forms.Application.Run() at emulator2.Program.Main()
The error points at this line:
HttpWebResponse l_WebResponse = (HttpWebResponse)l_WebReq.GetResponse();
Does anyone have any idea on how to solve this? I need to get this
solved real quick..so any help given is greatly appreciated! Thanks!
My guess is that the emulator doesn't have proper network connectivity. It can be a pain (and hit-and-miss in my experience) getting networking up and running on the old Windows Mobile emulators. (It's easy in Windows Phone 7.)
Load up Internet Explorer and see if that can make a connection to the same URL...
Additionally, you're not disposing of any of your resources (and if this code is really in a reference book exactly as you wrote it, that's a significant black mark against the book). For example, you should be disposing of the web response:
using (HttpWebResponse response = ...)
{
}
Likewise I would personally dispose of the response stream and the stream reader, just on general principle. I suspect that when the response is disposed, the stream will be too - but it makes sense to dispose of all streams etc unless you know you need to leave them undisposed.
If you're running in the emulator you'll ned to "cradle" the emulator and then create a partnership with ActiveSync (Win XP) or Windows Mobile Device Center (Vista or 7).
This will allow the emulator to share the network connection with the PC. You also need to do this even if you want to connect from the emulator to the PC.
As Jon mentions, in WP7 you don't need to make a connection in this way, the WP7 emulator automatically shares the network connection of the host PC.
Use IE Mobile (on the emulator) to check that the device can connect to the site.
Edit
To cradle the emulator, in VS2008 select "Device Emulator Manager" from the Tools menu. Select the emulator that's running, right click and select "Cradle".
Mobile Device Center should start automatically and ask if you want to create a partnership, just as if you'd connected a real device.

Why am I unable to get Site.State for an FTP site, when using Microsoft.Web.Administration?

Using the following C# code:
using System;
using Microsoft.Web.Administration;
namespace getftpstate
{
class Program
{
static void Main(string[] args)
{
ServerManager manager = new ServerManager();
foreach (Site site in manager.Sites)
{
Console.WriteLine("name: " + site.Name);
Console.WriteLine("state: " + site.State);
Console.WriteLine("----");
}
}
}
}
I get the following output:
C:\projects\testiisftp\getftpstate\getftpstate\bin\Debug>getftpstate.exe
name: Default Web Site
state: Stopped
----
name: Default FTP Site
Unhandled Exception: System.Runtime.InteropServices.COMException (0x800710D8): T
he object identifier does not represent a valid object. (Exception from HRESULT:
0x800710D8)
at Microsoft.Web.Administration.Interop.IAppHostProperty.get_Value()
at Microsoft.Web.Administration.ConfigurationElement.GetPropertyValue(IAppHos
tProperty property)
at Microsoft.Web.Administration.Site.get_State()
at getftpstate.Program.Main(String[] args) in C:\projects\testiisftp\getftpst
ate\getftpstate\Program.cs:line 17
Any ideas why I might be seeing the above 0x800710D8 COM error? I'm able to manage the FTP site just fine using IIS manager (I can start, stop, change settings, etc).
The first thing to clarify is that Site.State is a property to get the state of the HTTP protocol and for that reason my guess is that the site that is throwing that exception is probably NOT an HTTP site.
If you want to get the FTP state you need to do is:
int ftpState = Site.GetChildElement("ftpServer")["state"]
You can verify if a site is HTTP or not by inspecting the Site.Bindings and looking for the Protocol property, if it does not have HTTP or HTTPS you will get the exception above which you could safely ignore.
For more information: IIS.net FTP Settings / Sample Code
I think the answer is that this is just a bug in the Microsoft IIS API that we have to live with. I've opened a bug report on MS connect which has had 2 upvotes, however MS have shown no interest in this (and I doubt they will any time soon).
I don't believe there is a workaround for getting the actual state (as the question asks). Some have suggested that I should probe port 21, but this only tells me if there is an FTP server running, not what FTP server is running (as you can have multiple sites) -- so in some cases, this approach is completely useless.
The workaround to stopping and starting the site (which also causes a similar error) is to set auto-start to false on the FTP site and restart IIS (it's not great, but it works just fine).

Categories

Resources