I would like to create an app that will deploy a website. Basically, I just want this app to copy the publish files to the webserver in a new folder, change the website to that folder, then recycle the app pool.
I found out that I should be able to do this with Microsoft.Web.Administration. I am having a problem with even the most basic task as I'm learning how to do this. here is my code in a windows form app to just play with this.
try
{
using (Microsoft.Web.Administration.ServerManager sm = Microsoft.Web.Administration.ServerManager.OpenRemote("webservername"))
{
foreach (var site in sm.Sites)
{
MessageBox.Show(string.Format("{0}", site.Name));
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
I'm simply trying to loop through the websites and display the names as my first try. The error I get is the following:
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Web.Administration.Interop.IAppHostWritableAdminManager'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{FA7660F6-7B3F-4237-A8BF-ED0AD0DCBBD9}' failed due to the following error: Interface not registered (Exception from HRESULT: 0x80040155).
at Microsoft.Web.Administration.ConfigurationManager.CreateAdminManager[TClass,TInterface](WebConfigurationMap webConfigMap, Boolean isAdminConfig)
at Microsoft.Web.Administration.ConfigurationManager.CreateWritableAdminManager(WebConfigurationMap webConfigMap, String configPathToEdit, Boolean isAdminConfig)
at Microsoft.Web.Administration.ConfigurationManager.CreateConfiguration(WebConfigurationMap configMap, String configPathToEdit, Boolean isAdminConfig)
at Microsoft.Web.Administration.ConfigurationManager.GetConfiguration(String rawConfigurationPath, String cacheKey, Boolean isAdminConfig)
at Microsoft.Web.Administration.ConfigurationManager.GetApplicationHostConfiguration()
at Microsoft.Web.Administration.ServerManager.GetApplicationHostConfiguration()
at Microsoft.Web.Administration.ServerManager.get_SitesSection()
at Microsoft.Web.Administration.ServerManager.get_Sites()
The line that errored is:
foreach (var site in sm.Sites)
I've tried this with both my local IIS8 express and a windows server 2008 IIS 7.5
What have I done wrong?
You may want to check the following points:
The Name of the server. If not sure try looking for in your IIS Management
The version of the .dll is the right for your version of IIS.
The .net framework version. Since it use System.Web it depends on full-version of the .net framework but not on the Client Profile subset.
The machine on which the code is executing needs to have the IIS Management Scripts and Tools Windows feature installed.
On a Windows client OS or on Windows Server 2008 R2 and earlier, you can install it via the following steps:
Open Control Panel > Programs > Turn Windows features on or off.
Drill down to Internet Information Services > Web Management Tools and check IIS Management Scripts and Tools.
You are trying to manage a remote server, so
The account runs the code must be the local administrator of that remote server.
The DCOM ports must be opened at firewall.
Related
I've used a simple windows service to make a method work in specific time and it works fine. Following that I've already tried:
protected override void OnStart(string[] args)
{
this.WriteToFile("Simple Service started {0}");
this.ScheduleService();
}
protected override void OnStop()
{
this.WriteToFile("Simple Service stopped {0}");
this.Schedular.Dispose();
}
private Timer Schedular;
public void ScheduleService()
{
try
{
Schedular = new Timer(new TimerCallback(SchedularCallback));
string mode = ConfigurationManager.AppSettings["Mode"].ToUpper();
this.WriteToFile("Simple Service Mode: " + mode + " {0}");
//Rest of the code here
}
catch(Exception ex)
{
WriteToFile("Simple Service Error on: {0} " + ex.Message + ex.StackTrace);
//Stop the Windows Service.
using (System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController("SimpleService"))
{
serviceController.Stop();
}
}
}
This is done in a simple windows application. So what I am trying to do is to call a web service (A specific method to operate in a specific time) in a windows service. The application I am building is web-based and am little bit confused how would I integrate the windows service into it? Do I need any alternatives or any suggestions would be appreciated.
Note: What I would like to know is it required to create another project for windows service in the web application or any other way to implement?
To call a web service from a Windows Service application, you would first generate a DLL from that web service, then instantiate its namespace. Assuming you have the code for that web service and/or know its namespace, you can perform these commands to do this:
Perform these lines on a command line:
cd C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools
wsdl /l:CS /protocol:SOAP %svc%?WSDL
where %svc% is the URL for your web service, i.e. http://localhost:777/MyWebService.asmx
If the code is in VB instead of C#, change /l:CS to /l:VB.
This will output a proxy class file that can be converted to a DLL.
Move the MyWebService.cs file from C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools to the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ directory.
Run these two commands on the command line:
cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
csc /t:library %name%.cs /reference:System.Web.Services.dll /optimize
where %name% is the name of the class (without the .cs, since the command will append this). In our case, we'd use MyWebService. (Change .cs to .vb for a VB class.)
Navigate to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 via Windows Explorer. You should see a DLL created in that folder with the name of the class (MyWebService.dll). Copy this file to the bin folder of your Service project. You will need to set the bin folder to be included in your project, and right-click the folder to Add > Existing Item. Select the DLL. Once imported, select the DLL and change its properties to:
Build Action: Content
Copy to Output Directory: Copy if newer (or Copy always, as you prefer)
Right-click References > Add References. Navigate to the DLL in the bin folder for your web service.
Right-click References > Add Service References. Assuming your web service is running, take its full URL (i.e. http://localhost:777/MyWebService.asmx) and put that on the Address line. In the Namespace textbox, give it something more meaningful than ServiceReference1, but it should not be the same as MyWebService (the name/namespace of the ASMX file). Perhaps MWS.
Instantiate your web service in your Windows Service:
MWS.MyWebServiceSoapClient webService = new MWS.MyWebServiceSoapClient();
webService.Open();
string someDataYouWant = webService.SomeMethodToGetData();
webService.Close();
Or you can probably do:
MyWebService webService = new MyWebService();
string someDataYouWant = webService.SomeMethodToGetData();
webService.Dispose();
In answer to your query on my comment;
Another approach is to use an IIS Auto-Start website contaning your Windows Service logic. The IIS Auto-start is supierior to using a Windows Service as it contains all the IIS application hosting logic including auto-restart, and aggressive resource management. A poorly written Windows Service can take down a Server but it takes a lot for an ASP.net IIS hosted application to take down its host (its almost impossible).
Your Auto-Start website need not be visibile to the outside world - it just needs to have an internal timer that keeps it alive when it starts up. Note that the web application might be started and stopped by IIS for various reasons; but the outcome is that it will be running whenever your other web service application is running. The internal timer can wait for a specific time to execute the logic you need to call your second web service.
The key thing to remember is that a Windows Service is designed to be an application that is hosted by Windows and is continually running. An IIS application is designed to be run by Windows but runs only when called. The IIS Auto-Start website concept allows you to provide a "continually running" website but hosted by the robust IIS application hosting components, instead of it running directly as an OS process.
Generally people dont do this because either they dont know about it, or want to avoid needing the IIS infrastructure to run "Windows Service" type applications, but in your case you have already paid the cost of using IIS to host your second web service, so you may as well make full use of IIS (and avoid the second technology stack and deployment headaches of Windows Service deployment).
So I suggest using an IIS Auto Start in preference to a Windows Service in your situation because;
You only need to use on tech stack in your solution, which was what your OP was asking about
IIS carries out active resource management on all its applications, terminating, restarting as neccessary if they become non-functional. Windows Services do not have that capability.
Your IIS based service code is XCOPY deployable with no administrator access credentials on the target machine.
Your IIS service is hot upgradeable without needing OS level administrator rights - IIS handles the stopping and restarting on upgrade without you needing to do anything.
Running on Windows Server 2012 R2 Standard, with IIS 8.5.9600
In C#, after setting up a site, I'm retrieving the DefaultAppPool from the site.
Upon retrieval of the pool, the following properties have exceptions on them:
appPool.State:
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
appPool.WorkerProcesses
at Microsoft.Web.Administration.Interop.IAppHostElement.get_Collection()
at Microsoft.Web.Administration.ConfigurationElement.GetCollection(String collectionName, Type collectionType)
at Microsoft.Web.Administration.ApplicationPool.get_WorkerProcesses()
So I cannot call
AppPool.Recycle()
It throws this exception:
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at Microsoft.Web.Administration.Interop.IAppHostMethodInstance.Execute()
at Microsoft.Web.Administration.ConfigurationMethodInstance.Execute()
at Microsoft.Web.Administration.ConfigurationElement.ExecuteMethod(String methodName)
at Microsoft.Web.Administration.ApplicationPool.Stop()
at EBI.Core.Common.WebHelper.IISHelper.AddApplicationIis7(String serverName, String applicationPool, String siteName, String applicationPath, String virtualDirectoryPath, String physicalPath, String defaultPage, Int32 deploymentType, String siteUrl)
Online research says to add high privileges to this folder:
C:\Windows\System32\inetsrv\config
So I have increasingly added the following:
SYSTEM
Administrators
IIS_IUSRS
INTERACTIVE
NETWORK
SERVICE
DefaultAppPool
NETWORK SERVICE
CREATOR OWNER
IUSR
BUT STILL SAME ERRORS.
It's probably a bad idea to add all those rights to that folder, so perhaps there is something else I might be missing, but I cannot find what it is. Any ideas?
Thanks for any help!
Whether you are trying to access the app-pool from any console application or windows service? If so then the console application or windows service should be executed with a username which has admin rights on the server. The username should also be part of IIS_WPG group. May be I have got your question totally wrong.
If using c# code and deploying to IIS Server then running AppPool.Recycle() can generate 'Access is denied' error.
Visit the application pool you are running the c# code under, and go to advanced Settings -> Identity and change the Identity to 'Administrator' or some user with Admin rights.
I am in need of read a PPT/X PowerPoint File in C# code and display that in web form as image.
I did it using in VS 2013 C# .NET 4.0 and using dlls, Microsoft.office.interop.powerpoint.dll and Office.DLL.
It is working perfectly fine when running on local machine and working in local machine.
When I publish it on Azure Web Server or in Shared Server IIS,
I am ending up with
*
Error occurred: Retrieving the COM class factory for component with
CLSID {91493441-5A91-11CF-8700-00AA0060263B} failed due to the
following error: 80040154 Class not registered (Exception from
HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
*
I copied both DLLs into BIN folder.
Still no use.
Any idea how can i resolve this!!
Thanks in advance.
Just try enabling the fusion logs, it may be the case that your library is not signed and due to that your are getting this exception. Try disabling the strong name validation using sn -Vr
I'm working on web project that will run on Windows Azure Web role;
In the cloud, there will be 2 instances of the role;
I'm using co-located named cache (In-Role Cache) spread between 2 role instances;
Locally, I debug with single instance;
In the cloud, cache client is created successfully and work fluently;
When debug locally, I am unable to create instance of DataCacheFactory, because when the constructor is called, the program flow "stops" and doesn't continue to the following statement. There is no exception!
That's the code where I'm creating Factory and cache client:
var cacheFactoryConfig = new DataCacheFactoryConfiguration
{
ChannelOpenTimeout = TimeSpan.FromMinutes(2),
TransportProperties = {ReceiveTimeout = TimeSpan.FromSeconds(45)}
};
DataCacheFactory cacheFactory;
try
{
cacheFactory = new DataCacheFactory(cacheFactoryConfig);// <--stops here
}
catch (Exception e)
{
Trace.WriteLine(string.Format("--> Message-> {0}; --> Stack Trace->{1}", e.Message, e.StackTrace));
throw;
}
cacheClient = cacheFactory.GetDefaultCache();
Service configuration:
Cache client and server configuration in web.config
I would give any additional information if such is requested in order to resolve the problem shortly.
------EDIT 1------------------
Due to related post Making Windows Azure Caching Work in Compute Emulator I have to add some info:
Operating sistem -> Windows 7 Professional
IDE -> Visual Studio 2013 Ultimate Update 4
Windows Azure Caching package 2.4.0.0
Windows Azure SDK Version 2.4
I don't have Windows Server AppFabric installed, so I'm going for it!
After few days of investigation, I managed to solve the issue and successfully create instance of DataCacheFactory and DataCache and so on. The problem is described and solved in the following 2 posts:
https://social.msdn.microsoft.com/Forums/azure/en-US/8580689a-a1a1-4db7-bba9-f42c1a90e0db/windows-azure-webrole-caching-preview-hangs-makes-the-emulator-stuck-in-deploy-loop?forum=windowsazuredevelopment
http://blog.elastacloud.com/2012/06/09/using-the-windows-azure-cache-preview-with-sdk-1-7/
In my case, I had Microsoft Server AppFabric installed, so I removed it.
Just in case, I removed all available Windows Azure SDKs (2.4 was installed) and
all old nuget packages related to Azure Caching.
I did verify that all assemblies are removed from GAC too.
After "cleaning" I install again latest Azure SDK available which is 2.5. http://azure.microsoft.com/en-us/documentation/articles/cache-dotnet-how-to-use-in-role/
I would like to point out, that windows Event Viewer helped a lot. In Windows Azure logs I found an error that was happening when I start the web role with Azure Emulator. Error was thrown by CacheInstaller.exe -> MissingMethodExceprion with message:
Method not found:
'Microsoft.ApplicationServer.Caching.ClusterConfigElement
I am a .NET developer using C#. I am trying to connect to QC Version 11 server (64bit) but it's throwing an exception (Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))) when I call .InitConnectionEx method. I have installed QC client 11 on my development machine. My development machine is also 64 bit (Windows 7/2008). It looks like some QC dll is not getting registered during client installation on the local machine. I have written the below C# code for connection but I am receiving the issue on line 2.
TDConnection tdConnect = new TDConnection();
tdConnect.InitConnectionEx("http://192.168.1.10:8181/qcbin/");
tdConnect.ConnectProjectEx("DEFAULT", "Test", "admin", "admin");
Please help me to find out solution on priority.
Are you running your application with elevated privileges? It could be the application is not able to access the appropriate underlying COM object the .NET wrapper is trying to access...
Try installing the QC Connectivity Add in, I believe it registers all the components correctly and fixed this error for me.
11.52 and possibly other versions: from within QC Explorer > Help > ALM Tools > HP ALM Connectivity
QC 11: https://almpc.sqa.its.state.nc.us/qcbin/TDConnectivity_index.html
*If the quality center server was patched, you may have to login to QC and then copy all of the files from your appdata/local\HP\ALM-Client\alm folder into C:\ProgramData\HP\ALM-Client\alm