Host Multiple Wcf Services On Local IIS 6 - c#

I have tried to google a lot to find a solution to how to host multiple WCF web services on local IIS 6.
So i am asking here. If I can get a step of procedure then i would be glad.

To accomplish your goal this is how to do it:
Create your new solution or just reuse current solution you have.
Create new Project under Visual C# and select WCF Service Application. For sample purposes we name it MultipleHostService project.
It will produce three files named IService1.cs, Service1.svc and Web.config
Under your MultipleHostService project add another New item, under Visual C# Select WCF Service and leave name as is.
It will product addition two files named Iservice2.cs and Service2.svc
Open your Web.Config add Behaviors and Binding configuration highlighted with red box.
If you notice we added Services node and service under it? That is the part that allows us to specify multiple services.
Now click MultipleHostService project
Click Properties
Click Web Tab
In the Servers panel
Select Local IIS in the dropdown list
And under Project URL type this : http://localhost/MultipleHostService "You can change it later on if you want"
And click Create Virtual Directory.
Build the Project MultipleHostService ( Make it sure no failed shown in Error List )
Go to browser and type the follow:
http://localhost/MultipleHostService/Service1.svc
http://localhost/MultipleHostService/Service2.svc
You should see something in the browser like this:
Tools and settings I've used:
Visual Studio 2013
IIS 7
.Net Framework 4.5
Improvements :
You can refactor proper naming for your services.
Remove unnecessary XML node in the configuration file like unused behavior.
Disclaimer : I haven't tested it using IIS 6 but I'm confident that it works on IIS7. Configuration about IIS is not part of this topic so you migt run
some issues which I'm not aware of. There are also some other ways to accomplish multiple hosting of services but this topic is focusing on usage of configuration file. And please do some study on proper Bindings, Behavior and MetaDataExhange which I didn't discuss here.

Related

Visual Studio 2019 .NET CORE and React Template Subsite

I am having a hard time getting this template to work as a subsite.
The steps that I took to create the project were:
Launch Visual Studio
Create a new project
Select ASP.NET Core Web Application
Gave the details for where the project should be stored, etc
Create
At this time I am not interested in redux so I just selected the "React.js A project template for creating an ASP.NET core application with React.js"
After that I thought that the steps to make this work at a sub-site would be:
Right-Click and Properties on the Web App Project, on the debug tab I set the App URL to what was there + /mysub, for example: http://localhost:57197/mysub
Inside the Client App Folder I modified package.json and set the "homepage" to "/mysub"
When I debug the application nothing renders in the browser. The browser's console shows that it is getting invalid characters when trying to load resources such as manifest.json, and even bundle.js, which tells me that the client side router is probably intercepting the requests for those files, and when I look at the network tab it looks pretty more obvious that is what is going on. The strange thing is though that tag does appear to be right and thus it is setting the %PUBLIC_URL% environment variable as I would expect, but for some reason it just will not work at this subsite location. I suspect that maybe there is more that I may need to do in Startup.cs, or even appsettings.json but I am not sure what that might be, or if even that is the route to go. Any suggestions would be great.

Multiple copy of IIS Site, Databases and Windows services

I have a Big Application build in asp.net 4.5.1 Web form. The Application has two Windows Services. This is a product that we host for different vendors. The client Requirement is to have Separate URL, Database and separate Services. we are getting vendors rapidly, now this became a big problem for me, to update, each url separately, to trace any db changes across the database and implement that separately, and to create separate windows service applications for each vendor and to install that separately on the server. Although I have put code in class libraries so that is shared among all the web and the Windows Service application. but there are other settings, like encryption key, the connection strings to each database, the email settings etc.
can someone please guide me how can I manage multiple copy of same application when there are Windows Service applications too.
Thanks in Advance
I am doing similar things by using different build configurations for that.
Create a new build (solution) configuration for each customer. Right click solution and select 'Configuration Manager'.
Add new configuration with customer name and select to copy settings preferably from Release config.
Once you've done that you are able to switch between those configs next to the debug button in VS.
Go to your web project, right click your Web.config file and select 'Add config Transform'
New config files are created (Web.[ConfigName].config) and placed as sub node under the Web.config file.
These new files are used to transform the original Web.config depending on the selected solution configuration. There's some information in the transform file on how to use it, it is not difficult.
If you would go for automated build process later on, the solution config is the key for that as well. Also if you define publish templates (e.g. to create web deploy packages), you are able to select the config. The transformed web.config is then automatically put into the package.

Changing project port number in Visual Studio 2013

How can I change the project port number in Visual Studio 2013 ?
I'm using ASP.Net and I need to change the port number while debugging in Visual Studio 2013.
There are two project types in VS for ASP.NET projects:
Web Application Projects (which notably have a .csproj or .vbproj file to store these settings) have a Properties node under the project. On the Web tab, you can configure the Project URL (assuming IIS Express or IIS) to use whatever port you want, and just click the Create Virtual Directory button. These settings are saved to the project file:
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<DevelopmentServerPort>10531</DevelopmentServerPort>
...
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
Web Site Projects are different. They don't have a .*proj file to store settings in; instead, the settings are set in the solution file. In VS2013, the settings look something like this:
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "WebSite1(1)", "http://localhost:10528", "{401397AC-86F6-4661-A71B-67B4F8A3A92F}"
ProjectSection(WebsiteProperties) = preProject
UseIISExpress = "true"
TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.5"
...
SlnRelativePath = "..\..\WebSites\WebSite1\"
DefaultWebSiteLanguage = "Visual Basic"
EndProjectSection
EndProject
Because the project is identified by the URL (including port), there isn't a way in the VS UI to change this. You should be able to modify the solution file though, and it should work.
Right click the web application and select "properties"
There should be a 'Web' tab where http://localhost:XXXXX is specified - change the port number there and this will modify the configuration to use your new port number.
I usually start at 10000 and increment by 1 for each web app, to attempt to steer well clear of other applications and port numbers.
This has proved to be elusive for me (WebSite Project) until I figured out the following procedure, which combines the solution provided by #Jimmy, with the added step of checking out the solution from Source Control
Steps: (if using VS2013+ with website project and SourceControl)
Check out the Solution file only (from sourceControl) (this can be tricky. the easiest way to do this is to make a small change in the Solution file properties/settings and then undo if necessary)
Locate the solution file (e.g. solution.sln) in exploer, and open in text editor.
Locate the entry: VWDPort = ...... and change to desired port: (example: "60000" - depends on your IISExpress Settings)
save the change (will prompt to reload solution)
Well, I simply could not find this (for me) mythical "Use dynamic ports" option. I have post screenshots.
On a more constructive note, I believe that the port numbers are to be found in the solution file AND CRUCIALLY cross referenced against the IIS Express config file
C:\Users\<username>\Documents\IISExpress\config\applicationhost.config
I tried editing the port number in just the solution file but strange things happened. I propose (no time yet) that it needs a consistent edit across both the solution file and the config file.
Open Solution file (.sln) in Editable mode (Notepad or notepad++ or any other tool)
Find tag name VMDPort and update it to your desired port.
see below snap.
To specify a port for the ASP.NET Development Server
In Solution Explorer, click the name of the application.
In the Properties pane, click the down-arrow beside Use dynamic ports
and select False from the dropdown list.
This will enable editing of the Port number property.
In the Properties pane, click the text box beside Port number and
type in a port number. Click outside of the Properties pane. This
saves the property settings.
Each time you run a file-system Web site within Visual Web Developer,
the ASP.NET Development Server will listen on the specified port.
Hope this helps.
The Visual Studio Development Server option applies only when you are
running (testing) the Web project in Visual Studio. Production Web
applications always run under IIS.
To specify the Web server for a Web site project
In Solution Explorer, right-click the name of the Web site project for which you want to specify a Web server, and then click Property
Pages.
In the Property Pages dialog box, click the Start Options tab.
Under Server, click Use custom server.
In the Base URL box, type the URL that Visual Studio should start when running the current project.
Note: If you specify the URL of a remote server (for example, an IIS Web application on another computer), be sure that the remote server is running at least the .NET Framework version 2.0.
To specify the Web server for a Web application project
In Solution Explorer, right-click the name of the Web application project for which you want to specify a Web server, and then click
Properties.
In the Properties window, click the Web tab.
Under Servers, click Use Visual Studio Development Server or Use Local IIS Web server or Use Custom Web server.
If you clicked Local IIS Web server or Use Custom Web Server, in the Base URL box, type the URL that Visual Studio should start when
running the current project.
Note: If you clicked Use Custom Web Server and specify the URL of a remote server (for example, an IIS Web application on another computer), be sure that the remote server is running at least the .NET Framework version 2.0.
(Source: https://msdn.microsoft.com/en-us/library/ms178108.aspx)
Steps to resolve this:
Open the solution file.
Find the Port tag against your project name.
Assign any different port as current.
Right click on your project and select Property Pages.
Click on Start Options tab and checked Start URL: option.
Assign the start URL in front of Start URL option like: localhost:8080/login.aspx
This is the only solution that worked for me after trying several of those above. Switch to your c:\users folder and search for .sln and then remove all .sln files that have your project name. Then restart your computer and rebuild the solution (F5) and it worked!

How Can I Host A WCF App In IIS?

I'm following Microsoft's tutorial on the topic here but it's not working and several items are unclear to me.
http://msdn.microsoft.com/en-us/library/ms733766.aspx
In step 2 it says, "ensure that ASP.NET has access to the contents of the folder". How can i do this?
Is it correct that the .cs code not be compiled? I've never ran .cs as a script of any kind.
Here is my error:
HTTP Error 404.17 - Not Found
The requested content appears to be script and will not be served by the static file handler.
Thanks.
Could you please ensure that your apppool in which your site is running in "Integrated" mode rather than Classic.
If the problem is not resolved after doing this, try to register your IIS with .netv4.0
For doing that
Go to Command Prompt
Go to the location C:\Windows\Microsoft.NET\Framework\v4.0.30319
Register the IIS using aspnet_regiis -i command
Open IISManager and go to handler mappings and right click on the static file and select "Revert to Parent"
You can Host a WCF App/Service in IIS as you host simple website. It seems to me that you are trying to access/browse .cs file. If so, then it is not possible as it is code file. You should browse only your service file i.e. .svc file.
You can refer http://adarshdchaurasia.wordpress.com/2013/09/26/create-restful-wcf-service-api-using-get-post-step-by-step-guide/ to create a WCF service.
Please ensure that:
You have .Net framework 4.0 installed and enabled on your machine. If
not, install or try to re-install. Sometimes re-installation fix the
unknown settings problem we accidentally create.
First try to host a simple demo web site to check if the problem is
with your WCF application or with hosting process your are
following.
In step 2 it says, "ensure that ASP.NET has access to the contents of
the folder". How can i do this?
I think it mean make sure your folder are accessible by the IIS_IUSRS
Check the publish folder properties -> Security tab -> group or user name.
Make sure the app is using application pool with correct .net framework version.
normally I will just set .net framework v4.0.30319

Parser Error : Could not create type

I have created webservice and published it on local machine. Then I have uploaded it on server.
Now while I tried to access webservice it gives following error :
Parser Error Message: Could not create type 'webservice.myservice'
Source Error:
Line 1: <%# WebService Language="C#" CodeBehind="myservice.asmx.cs" Class="webservice.myservice" %>
I tried This link but unable to solve my problem.
What should I do?
I don't know if this is dragging something up from the dim and distant past, but I had this problem. I fixed it. So I thought I'd to share it.
When you create a web service in Visual Studio (I'm using 2010 but I'd imagine it's the same for others), it creates a file called Service1.asmx
You will be tempted to rename it to MyService.asmx (or whatever).
Then you'll look inside and see the line
public class Service1: System.Web.Services.WebService
which you'll change to
public class MyService: System.Web.Services.WebService
and then when you try running it, you get the error
Could not create type 'MyProject.MyService'
Because it still thinks the class is called Service1.
If you right click the .asmx file and select view markup, you'll see it still says:
<%# WebService Language="C#" CodeBehind="MyService.asmx.cs" Class="MyProject.Service1" %>
change it to
<%# WebService Language="C#" CodeBehind="MyService.asmx.cs" Class="MyProject.MyService" %>
save it, try it.
It worked for me.
I had the same problem and looked for it for a long time!
I tried a lot of things including the following:
Frameword version incorrect
A whole list of things that could be wrong
None of those worked for me. After some searching, testing and cursing, I finally found the problem: The application (webservice) was incorrectly hosted.
Let me explain with a little background:
I had a project containing two solutions: One solution was the website that I made (html, javascript, etc), the other solution contained a folder with the business logic, the database model and the webservices. Obviously the webservices folder contained my .asmx files and code-behind for them.
Project
Data Core
Database Model
Business Logic
Webservices
myWebservice.asmx
Website
I was hosting these in the following way:
My website was hosted as a new site with the website folder as root folder
My webservices I was hosting as an application in my website, with the webservices folder as root
More visually:
IIS 7
My Website => Pointing at the "Website" folder
Webservices Application => Pointing at the "Webservices" folder in the Data Core
This resulted in the following url "http://website/webservices/myWebservice.asmx", which gave me the "Could not create type" error.
Now, after playing around a bit I tried hosting my webservice application starting with the data core as root, instead of the webservice folder.
Visually:
IIS 7
My Website => Pointing at the "Website" folder
Webservices Application => Pointing at the "Data Core" folder.
Obviously using the same url as before would give me a "File not found" error. However, using the following url "http://website/webservices/webservices/myWebservice.asmx",I finally got my working webservices page!
A small url breakdown:
http ://website/ => My website from the "Website" folder
webservices/ => Equivalent to the "Data Core" folder
webservices/ => The "webservices" folder in the "Data Core" folder
myWebservice.asmx => The webservice file in the "webservices" folder, in the "Data Core" folder
I assume that because I was hosting my webservices directly from the "webservices" folder in the Data Core, that the server could not find the compiled DLL of the webservices (which resides in the "bin" folder), since I was hosting at a deeper level.
After changing the configuration and hosting the webservices from the "Data Core" folder, the IIS server could "see" the bin folder and host the webservices succesfully. When using the correct url that is ^_^
I hope this is clear and helps you with you problems!
Another thing that can cause the problem. Is not creating an application for the project through the IIS itself. If the code is already on the server navigate to it in IIS from the left Connections pane. If the web site directory is still a yellow folder icon (and not a globe icon) you need to right-click on it and choose Convert to Application otherwise follow these steps...
Start -> Search For IIS
Open It!!
Right Click on the Default Web Site or the web site you are planning to publish the service to it.
Add application... Enter an Alias ex. "MyWebService" ... Choose the physical path. in my case was C:\inetpub\wwwroot\MyWebService which is my default web site path.
Then when you publish through Visual Studio choose that folder. or just copy your code files to it.
I'm fairly certain this is just a summary of what Glenn said, but I ran into this issue because my application was created from the directory one level too high in the directory structure.
For example, my web service was in SiteProject_1/SiteProject_2/service.asmx
Originally SiteProject_1 was what I converted into the application within IIS. I was able to resolve the issue by removing that application within IIS and instead making SiteProject_2 into the application.
I was having this problem this morning and Google landed me here, but none of these answers worked for me. But I did figure out what was wrong - at least in my case - so I thought I'd share it in case it helps others.
I had a web service that had been working fine for months in a solution with other parts of the application that I work on. Yesterday, I needed to fix something in a release branch, so I opened Visual Studio on a copy of the solution in another directory. Visual Studio decided to be helpful and silently remap all my virtual directories in IIS to where the programs would be in the release folder (if I had bothered to build them, which I hadn't). Now when I tried to hit my web service, IIS was pointing to the release version which had the asmx but no bin folder.
Opening the Web properties tab in my development solution and clicking the Create Virtual Directory remapped it back to the development version and all was good with the world again.

Categories

Resources