IIS 7.5 and IIS 8.0 European Hosting

BLOG about IIS 7.5 Hosting, IIS 8.0 Hosting and Its Technology - Dedicated to European Windows Hosting Customer

IIS Hosting Europe - HostForLIFE :: IIS Hosting of WCF Service

clock February 17, 2023 09:08 by author Peter

First let's create a simple WCF Service.


Step 1
Open Visual Studio and select "File" -> "New" -> "Project...". The following screen will open.

Select WCF Service Library and provide the name of the service as CarService. You can use whatever name for the service as you wish.

You will be able to see the following screen.

Step 2
Delete the Iservice1.cs and Service1.cs files from the project.

Step 3
Then add the two files IProduct.cs (interface file) and ProductService.cs to the project.

Step 4
In IProduct.cs (the interface file) write the following code.
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using System.ServiceModel; 
     
    namespace NorthwindServices 
    { 
        [ServiceContract] 
        public interface IProducts 
        { 
            [OperationContract] 
            string GetProductName(); 
     
            [OperationContract] 
             string GetProductQty(); 
     
            [OperationContract] 
             string GetCategoryName(); 
        } 
    }


Step 5
In the ProductService.cs file call the Interface file and write the definition of the Interface methods.
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
     
    namespace CarService 
    { 
        public class ProductService:IProduct 
        { 
            public string GetCarName() 
            { 
                return "Ford Figo"; 
            } 
     
            public string GetCarColor() 
            { 
                return "Sea Gray"; 
            } 
     
            public string GetQuantity() 
            { 
                return "1"; 
            } 
        } 
    }


Step 6
Now make the following changes in the App.config file.

    <?xml version="1.0" encoding="utf-8" ?> 
    <configuration> 
     
      <system.web> 
        <compilation debug="true" /> 
      </system.web> 
      <!-- When deploying the service library project, the content of the config file must be added to the host's  
      app.config file. System.Configuration does not support config files for libraries. --> 
      <system.serviceModel> 
        <services> 
          <service name="CarService.ProductService"> 
            <endpoint address="" binding="wsHttpBinding" contract="CarService.IProduct"> 
              <identity> 
                <dns value="localhost" /> 
              </identity> 
            </endpoint> 
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
            <host> 
              <baseAddresses> 
                <add           baseAddress="http://localhost:8732/Design_Time_Addresses/CarService/Service1/"/> 
              </baseAddresses> 
            </host> 
          </service> 
        </services> 
        <behaviors> 
          <serviceBehaviors> 
            <behavior> 
              <!-- To avoid disclosing metadata information,  
              set the value below to false and remove the metadata endpoint above before deployment --> 
              <serviceMetadata httpGetEnabled="True"/> 
              <!-- To receive exception details in faults for debugging purposes,  
              set the value below to true.  Set to false before deployment  
              to avoid disclosing exception information --> 
              <serviceDebug includeExceptionDetailInFaults="False" /> 
            </behavior> 
          </serviceBehaviors> 
        </behaviors> 
      </system.serviceModel> 
     
    </configuration>


As you can see we are using wsHttpBinding. The Service name is <service name="CarService.ProductService"> Contract is contract="CarService.IProduct">,
dns value="localhost" /> & baseaddress is baseAddress="http://localhost:8732/Design_Time_Addresses/CarService/Service1/"/>.

Step 7
Now run the project. If you see the following screen then your WCF Service is working perfectly.

You can invoke the methods and get the results to test the service.

Step 8
Now add the SVC file to the project so that we can use this file later to publish on IIS.
Right-click on the project then select Add -> New Item then select Text File.

Give the name of the file as CarServiceHost.svc

Step 9
Just make the following changes in the SVC file.
    <%@ ServiceHost Service="CarService.ProductService" %>

Step 10
Now build your solution then publish the project.

Give a target location on your hard drive.


Step 11
Now for the important part to host this service on IIS.
Go to Run -> inetmgr.

The following screen will open.


Click on Sites then select Add website.


Give the name of the service as CarService and select Application Pool as ASP.NET v4.0 as in the following:


Give the physical path of the service to the location where you have placed the published SVC file.

Give the port as 7742.


Now just open the browser and for the URL provide "http://localhost:7742/CarServiceHost.svc" or "http://ipaddress:7742/CarServiceHost.svc".The following page will open:

And that's it. You have successfully created and hosted a WCF Service on IIS. You can consume the service in an application and use it.



IIS Hosting Europe - HostForLIFE :: Configure Your ASP.NET Core App For IIS

clock February 2, 2023 06:33 by author Peter

The first thing you will notice when creating a new ASP.NET Core project is that it’s a console application. Your project now contains a Program.cs file, just like a console app, plus the following code:

public class Program
{
    public static void Main(string[] args)
    {
        var host = new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup()
            .Build();

        host.Run();
    }
}

What is the WebHostBuilder?
All ASP.NET Core applications require a WebHost object that essentially serves as the application and web server. In this case, a WebHostBuilder is used to configure and create the WebHost. You will normally see UseKestrel() and UseIISIntegration() in the WebHostBuilder setup code.

What do these do?
UseKestrel() – Registers the IServer interface for Kestrel as the server that will be used to host your application. In the future, there could be other options, including WebListener which will be Windows only.
UseIISIntegration() – Tells ASP.NET that IIS will be working as a reverse proxy in front of Kestrel and specifies some settings around which port Kestrel should listen on, forward headers and other details.

If you are planning to deploy your application to IIS, UseIISIntegration() is required

What is AspNetCoreModule?
You may have noticed that ASP.NET Core projects create a web.config file. This is only used when deploying your application to IIS and registers the AspNetCoreModule as an HTTP handler.
Default web.config for ASP.NET Core:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
  </system.webServer>
</configuration>


AspNetCoreModule handles all incoming traffic to IIS, then acts as the reverse proxy that knows how to hand traffic off to your ASP.NET Core application. You can view the source code of it on GitHub. AspNetCoreModule also ensures that your web application is running and is responsible for starting your process up.

Install .NET Core Windows Server Hosting Bundle
Before you deploy your application, you need to install the .NET Core hosting bundle for IIS – .NET Core runtime, libraries and the ASP.NET Core module for IIS.

After installation, you may need to do a “net stop was /y” and “net start w3svc” to ensure all the changes are picked up for IIS.

Steps to Deploy ASP.NET Core to IIS
Before you deploy, you need to make sure that WebHostBuilder is configured properly for Kestrel and IIS. Your web.config file should also exist and look similar to our example above.

Step 1: Publish to a File Folder

Step 2: Copy Files to Preferred IIS Location
Now you need to copy your publish output to where you want the files to live. If you are deploying to a remote server, you may want to zip up the files and move to the server. If you are deploying to a local dev box, you can copy them locally.

For our example, I am copying the files to C:\inetpub\wwwroot\AspNetCore46

You will notice that with ASP.NET Core, there is no bin folder and it potentially copies over a ton of different .NET DLLs. Your application may also be an EXE file if you are targeting the full .NET Framework. This little sample project had over 100 DLLs in the output.

Step 3: Create Application in IIS
While creating your application in IIS is listed as a single “Step,” you will take multiple actions. First, create a new IIS Application Pool under the .NET CLR version of “No Managed Code”. Since IIS only works as a reverse proxy, it isn’t actually executing any .NET code.

Second, you can create your application under an existing or a new IIS Site. Either way, you will want to pick your new IIS Application Pool and point it to the folder you copied your ASP.NET publish output files to.

Step 4: Load Your App!
At this point, your application should load just fine. If it does not, check the output logging from it. Within your web.config file you define how IIS starts up your ASP.NET Core process. Enable output logging by setting stdoutLogEnabled=true. You may also want to change the log output location as configured in stdoutLogFile. Check out the example web.config before to see where they are set.

Advantages of Using IIS with ASP.NET Core Hosting
Microsoft recommends using IIS with any public facing site for ASP.NET Core hosting. IIS provides additional levels of configurability, management, security and logging, among many other things. One of the big advantages to using IIS is the process management. IIS will automatically start your app and potentially restart it if a crash were to occur. If you were running your ASP.NET Core app as a Windows Service or console app, you would not have that safety net there to start and monitor the process for you.



About HostForLIFE.eu

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2016 Hosting, ASP.NET Core 2.2.1 Hosting, ASP.NET MVC 6 Hosting and SQL 2017 Hosting.


Tag cloud

Sign in