not able to test asp.net web service from remote machine - c#

we have built a asp.net web service application that we test on the local machine.
We have deployed it on the client's server and tested it there as well.
The web service returns JSON data, not xml.
But when the we try to access that URL from a remote machine, we cannot see the input fields for taking the parameters. it shows the list of the methods in the web service but when we click on them there's no text fields for input.
We'd like to access the web services remotely and test them.
Any help would be appreciated.

You'll want to make sure you have the following in your config file.
<configuration>
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
Really though you should probably be using something like SoapUI for testing services as the tests are re-runnable ect.

Related

.net core 2.0 app blocks plesk-webstat

I published an aps.net core 2.0 mvc app to a shared web hosting server that uses Plesk as control panel. The app works fine. However, I got the following error message when trying to access the web statistics:
This example.com page can’t be found
No webpage was found for the web address: https://example.com/plesk-stat/webstat/
HTTP ERROR 404
I contacted their support and got the answer "the .net core application settings aren't allowing the webstats to load. We recommend you consult with an experienced website developer to customize the web.config code accordingly for the website.", but they don't know how to configure the web.config file.
I really want to make the webstat to work. Any suggestion will be appreciated.
If URL Rewrite is blocking the access, try adding this string to the <conditions> section of the rule which is affecting webstat page:
<add input="{REQUEST_URI}" pattern="^/(plesk-stat/webstat)" negate="true" />
If that does nor help, configure failed request tracing to find which exact module is performing a redirect.
Along with changes in the web.config of the ASP.Net Core site itself to send the /plesk-stat/ url to IIS, a web.config must be added in the following directory:
C:\Inetpub\vhosts\{domain.tld}\.plesk\statistics\{domain.tld}\
(replace {domain.tld} with your domain), with the following contents:
<configuration>
<system.webServer>
<handlers>
<remove name="aspNetCore" />
</handlers>
</system.webServer>
</configuration>
This has to be done by the hosting provider on the server. Maybe you should contact the support of your hosting provider.

Create a connection string / connect to a database in asp.net?

I am trying to publish a website to make it go live and need to connect to a database. Currently I am using:
<connectionStrings>
<add name="UniversityContext" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=RoomAudit;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\RoomAuditSystem.mdf" providerName="System.Data.SqlClient" />-->
</connectionStrings>
in my web.config which obviously using my local machine.
I've looked online and on here and can't seem to find a clear cut tutorial. Here is the database details:
DATABASE SERVER
mysql4.gear.host
with my username and password with reading and writing permissions.
If someone could point me in the right direction I would appreciate it - I'm also using Entity Framework if that makes any difference?
EDIT:
This is my new connection string:
<add name="UniversityContext" connectionString="Server=mysql4.gear.host;Database=databasename;User Id=username; Password=password;" providerName="System.Data.SqlClient" />
However, when I publish the website I get a runtime error?
Runtime error:
Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a tag within a "web.config" configuration file located in the root directory of the current web application. This tag should then have its "mode" attribute set to "Off".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
Console error:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
IMO, best place for learning to write connection strings is here: https://www.connectionstrings.com/sql-server/
Try this
<add name="UniversityContext" connectionString="Data Source=mysql4.gear.host;Initial Catalog=databasename;User ID=username;Password=password" />
I suggest to create file with .udl extension and test configuration.
It could help you to find proper parameters.

Deploy REST service without access to IIS

I have developed a .NET REST web service in C#. While I have plenty of C# experience, I unfortunately do not have much understanding in deploying such a service in a web hosting environment.
Due to the environment, I do NOT have access to IIS.
The advice I have been provided with by the support services of the hosting provider is as follows:
Create a subdomain of the main domain to achieve a dedicated application pool (this a requirement of the host provider)
Create a Bin folder to hold my compiled libraries of source code
Add the following to the Web.Config file:
<system.web>
<httpHandlers>
<add type="ReportRESTWebService.Service, ReportRESTWebService" verb="*" path="report" />
</httpHandlers>
</system.web>
<system.webServer>
<handlers>
<add name="report" path="report" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="File" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" />
</handlers>
<directoryBrowse enabled="false" />
</system.webServer>
The above would have the effect of creating a handler mapping for the report resource on all HTTP verbs and forwarding any HTTP traffic on that resource to my ReportRESTWebService.dll for handling.
The point I am unclear on is whether the above will be satisfactory and how do I test whether the advice I am given is correct. I know that I have the site running locally but I have access to IIS so I have control over the configuration.
Hopefully somebody can help.
Thanks
If you are using Wcf Rest,then you can probably consider hosting it as as windows service
or self hosted service.
Windows Service
http://blogs.msdn.com/b/juveriak/archive/2009/03/15/rest-endpoint-hosted-in-a-wcf-windows-service.aspx
Self hosted Service
http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/self-hosted-wcf-rest-service-or-hosting-wcf-rest-service-in-console-application/
It would seem, after a day of exhaustive testing, that the steps I had taken (detailed in the question) would be satisfactory.
One point to watch out for is the matching Managed Pipeline Mode for your application pool. Failure to match this up correctly with your Web.Config will result in pain.

How to publish Silverlight site using a domain service?

I have a Visual Studio 2010 solution with 2 projects. One is a Silverlight client, the other a web site to which I added a domain service. It works fine when debugging in Cassini, but when I publish to IIS I get nothing returned from my entity query.
I'm not even sure where to start as this is my first attempt at doing this.
A few things:
Developing on Cassini (don't do it if you can avoid it)
It's always better to develop against IIS itself. There are differences between IIS and Cassini which can bite you if you aren't aware of them and it just makes more sense; you should always develop as close to the environment that you are develping for. Unless you are deploying to Cassini (and you aren't, no one does) then there's no point in developing against it unless you simply can't (you don't have a local install of IIS).
Web Deploy
Install Web Deploy on the IIS server you are going to deploy to. Once you do that, you can right click the web/domain project in your solution and select "Build Deployment Package".
Then, you will get a package that you can use with Web Deploy which will deploy everything (Silverlight, ASP.NET components, etc, etc) your project to IIS with a simple command-line call.
This was a very stupid, newbie issue. I used SQL Server Profiler to watch the queries come in and realized the account being used to authenticate against SQL Server was the server's computer account. I secured the Domain Service's methods and allowed the computer account access tot he DB.
Deploying to IIS might have some issues. I'd like to see what errors messages you're getting. Without these information it will become pretty difficult to give you an advice.
PS: I'm gonna assume that your WCF RIA services have valid definition ;-).
Based on my experience, this is the minimum config file, but it certainly will require more settings if you're consuming Authentication Domain Services or Data domain services (such as LinqToEntities or LinqToSql domain services):
Make sure your IIS have all the sections required by WCF RIA
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.serviceModel">
<section name="domainServices" type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" allowDefinition="MachineToApplication" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web>
<!-- You might need identify tag if you app requires additional permission to run -->
<!-- See you want to see more details when a error happens -->
<customErrors mode="Off"/>
<compilation debug="true" targetFramework="4.0" />
<!-- If your application uses authentication and authoriztion then -->
<!-- Elements required required for authentication: authentication and membership and probably roleManager -->
<httpModules>
<add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<add name="DomainServiceModule" preCondition="managedHandler"
type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</modules>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
Make sure the WCF RIA services are up and runnning
Try to access the WCF RIA service by using a web browser. Usually the service you're exposing has format like:
http://[hostname]/[namespacename]-[classname].svc
So, you should be able to hit the URL and see an output like:
Make sure DLLS are available
There are two options to deploy the WCF RIA dlls in the server side. You can indicate to the application that DLLs should be copied into the bin folder of your application or you can run the WCF RIA installer in server mode.
Accessing the services from the client
If the services are up and running they should be reachable to your Silverlight client. If there is an error you can start tracing by enabling WCF RIA debugging.
See http://blogs.msdn.com/b/saurabh/archive/2010/03/16/ria-services-application-deployment.aspx for more details about it.

dynamically set WCF baseAddressPrefixFilters

I have a WCF service that I am deploying in a shared hosting environment. Because of this I have to specify baseAddressPrefixFilters (see answer here for why this is necessary). Setting the base address prefix filters happens in the web.config like so...
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://example.com"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
The problem is that I have multiple environments that are configured this way with their own urls (i.e. dev, test, prod)
I tried the following with no luck...
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://dev.example.com"/>
<add prefix="http://test.example.com"/>
<add prefix="http://example.com"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
So the question is how do I set the baseAddressPrefixFilter dynamically at runtime?
If you are running under IIS7, this is a good walk through of the problem and solution. If not, the information for the WCF side is still what you need to know to resolve your issues.
http://keithelder.net/2008/04/28/configuring-wcf-and-iis-7-with-http-bindings-and-multiple/
Have you looked at the ServiceHostFactory? We used this in our 3.0 services to work with the different host headers.
http://blogs.msdn.com/rampo/archive/2007/06/15/supporting-multiple-iis-bindings-per-site.aspx

Categories

Resources