Reuse Windows Service classes - asp.net

I have a ASP Net project of the type Windows Service.
When I build that project an exe file is generated.
Now I also have another project os the type Web Service, that uses classes from the previous Windows Service project.
When I build the Web Service, on it's bin/debug folder, the Windows Service exe is there, instead of a DLL.
This way, when I deploy the Web Service on ISS, I get an exception when the part of the code that instatiates a class on the Windows Service project is executed.
The only whay I found to solve this issue, is to make the output type of the Windows Service to DLL instead of EXE, and the Web Service runs correctly.
But, of course, when I try to install the Windows Service, I get this error:
Can I even do this?

Windows Services and web services are different project types. You cannot run the same executable. You have to options:
Either you put the common code into a class library and create a project for the windows service and one for the webservice
You create to build targets.
Option 1 seems to be easier for me

Related

Debugging .NET dll in Service called from Unit Test

The Setup
I have a ASP.NET Web API v2 application that makes use of a .NET assembly (dll) to handle database updates (I will call it dbSttuff.dll). This dll is used inside one of the services that my API endpoint calls.
The method I am calling in the dll is failing for some reason and I am trying to step into the dll to see what is going on. However, I cannot seem to step into the dll.
What I have done
I have both the dbStuff.dll and dbStuff.pdb files in the bin folder of my API project.
I have made sure that Enable Just My Code is unchecked in my debug options in visual studio.
In my past experience I should be able to step right into the dbStuff.dll yet when I do the application crashes. I am wondering if it has anything to do with the fact that I am calling the service that uses the dbSTuff.dll from a Unit Test? I am using XUnit and running "Debug Selected Test" from the Test Explorer in Visual Studio.

How to call COM dll from c# web service using IIS

I wrote a web service (c#, VS2012, windows7 64bit), which calls a COM dll.
Using visual studio, there was no problem to execute the web service and thus the client's application.
After trying to locate the web service in the IIS, all calls to the COM dll's function failed.
What could be the problem? Is there any specific configuration of the IIS for COM dlls?
Try to change the executing user of the app pool to a custom account instead of a built-in account. Try to run it as an administrator first and get it to work. Then try with a more restricted user account.
I changed Framework version from 3.5 to 4. then sloved.
ref: http://quickstartprojects.org/2011/11/webservicesindotnet4/

Switching between azure/on-prem specific assemblies at runtime or pre-build based on config

I have a wcf web service which could be deployed to azure or on-prem.
I am trying to have a common code base for both scenarios but with different web.config for each sceanrio.
The problem is that when the wcf service is deployed on azure it needs to talk to azure cache instance and if deployed on prem it will talk to windows app fabric cache server.
the code to talk to both remains the same because they are the same caching product essentially.
However - if the wcf service is going to talk to azure cache then the project should have a reference to the following assemblies:
Microsoft.ApplicationServer.Caching.Core.dll (1.0.4817.0)
Microsoft.WindowsFabric.Common.dll (1.0.5627.0)
Microsoft.ApplicationServer.Caching.Client.dll (1.0.4817.0)
Microsoft.WindowsFabric.Data.Common.dll
Microsoft.ApplicationServer.Caching.AzureCommon.dll
Microsoft.ApplicationServer.Caching.AzureClientHelper.dll
If the code has to talk to app fabric on prem then the following assemblies have to be referenced.
Microsoft.ApplicationServer.Caching.Core.dll (1.0.4632.0)
Microsoft.WindowsFabric.Common.dll (1.0.4619.0)
Microsoft.ApplicationServer.Caching.Client.dll (1.0.4632.0)
Microsoft.WindowsFabric.Data.Common.dll
I am looking for a solution so that I can keep the same code base (.cs files and .csproj) and with a configuration switch in web.config it should refer to the right assemblies,
for example if 'UseAzure = 1' in web.config then the azure cache client side dlls should be referenced and loaded and if 'UseAzure = 0' then AF on-Prem dlls should be loaded.
I am wondering if this is possible using run time C# code or via a visual studio pre/post build task.
I am open to any other ideas to acheive this.
Could someone confirm on the feasability of these two options and if so point me to some code which does something similar.

Where is web.config file when running Azure web role in Compute Emulator?

I created an empty Azure Cloud Service project, then added a web role there. The role project has a web.config file.
When I hit F5 the role is deployed in Compute emulator. I went into the folder where role binaries are deployed - there's no web.config file there.
What's happening? Is that because I didn't set "copy always" on web.config file? What web.config does my role use?
If your role is configured for Full IIS mode (for those unaware of the difference between Hosted Web Core and Full IIS, see this blog post), the compute emulator should deploy the web role to IIS where it can be viewed in IIS Manager. On my machine (I'm running Azure SDK 1.5), the deployed web role's physical path is my source code directory.
I think web.config is compiled into your assembly as content in your development environment, and is not directly accessible like in staging/prod. You don't need to use Copy Always, if its marked as Content its all you need. You can use Environment.CurrentDirectory to see your web root path.
Even though the preferred way of storing configuration in Windows Azure applications is in the ServiceConfiguration.cscfg file, there are still many cases when you may want to use a normal .NET config file - especially when configuring .NET system components or reusable frameworks. In particular whenever you use Windows Azure diagnostics you need to configure the DiagnosticMonitorTraceListener in a .NET config file.
When you create your web role project, Visual Studio creates a web.config file for your .NET configuration. While your web application can access this information, your RoleEntryPoint code cannot-because it's not running as a part of your web site. As mentioned earlier, it runs under a process called WaIISHost.exe, so it expects its configuration to be in a file called WaIISHost.exe.config. Therefore, if you create a file with this name in the your web project and set the "Copy to Output Directory" property to "Copy Always" you'll find that the RoleEntryPoint can read this happily. This is one of the only cases I can think of where you'll have two .NET configuration files in the same project!
All info is from Azure Team Blog and I have used this solution successfully- http://blogs.msdn.com/b/windowsazure/

Runtime Error with referenced WCF Service

I have created a reference to an IIS hosted WCF service in my ASP.NET website project on my local workstation through the "Add Service Reference" option in Visual Studio 2008. I was able to execute the service from my local workstation.
When I move the ASP.NET web site using the "Copy Web Site" feature in Visual Studio 2008 to the development server and browse to the page consuming the service, I get the following error:
Reference.svcmap: Specified argument
was out of the range of valid values.
Has anyone experienced this same error and know how to resolve it?
EDIT: My development server is Win2k3 with IIS 6
The problem may be due to a mismatch with the solution/project folder structure and the IIS web site folder structure. I ran into similar problems a good while ago and ended up changing how I deploy web services. Here and here are some discussions of similar problems to yours, they ended up not using the Add Service generated client and rolled their own client. Also, I can vouch for using the "Publish web site" method for deploying my services. Here is a good article on web service deployment models.
#Sixto Saez: I was able to use the following resource similar to the one you provided to generate a proxy class using the ServiceModel Metadata Utility Tool (svcutil.exe).
Here is the exact command line:
svcutil /t:code http://<service_url> /out:<file_name>.cs /config:<file_name>.config
Here is the reference I found that suggested using the method.
Also, I was able to consume the service by creating a reference using the Visual Studio 2008 "Add Web Reference" command. It generates code based on .NET Framework 2.0 Web Services technology.
Unforunately, the WCF service web site and I can not use the svcutil solution (Unless you know of a way how...). Do you deploy you service or your web site with the service reference using Visual Studio 2008 publish web site feature?

Resources