Difference between website's access and web service's acess - c#

Following this question, I've met another problem where the request just doesn't go through. When I was first given the task, the website was working like so :
Website -> Web Services -> Library -> External Server (TextML Server for those who might be familiar with it).
I was asked a couple of things and of them was to get the web service layer out of the way to improve performance, like this :
Website -> Library -> External Server
So I went through the code and made the proper changes but I faced a problem where authentication was a problem, I asked the question and found the solution. Now the Website use the correct user to connect with the External Server. But then the method connecting with this particular server just run and goes on, and on, and on.... forever.
So the question is quite simple :
Is there a difference for the External Server either its a Web Service or a website that's is trying to establish a connection?
I use c#, asp on Windows XP and when I debut I use the local IIS which runs IIS 5.0 (I know its kinda old)
Also, one point to note if that if inside the same method, I use the webservice from my website to connect, it works and then the next line of code I use the library, it doesn't.
Example code :
WsDocServerService.DocServer doc = new WsDocServerService.DocServer();
XmlDocument oIndexList = new XmlDocument();
oIndexList = doc.GetSystemDocument(INDEX_FILE);//This will work
oIndexList = DocServerController.GetSystemDocument(INDEX_FILE);//This wont
//But both way I use the DocServerController.GetSystemDocument(filename); to get the file
Thanks a lot!
Although, I don't need a solution, maybe a proper answer could help me to solve the problem!
EDIT
The web service method called above is calling the controller method :
DocServerController.GetSystemDocument(INDEX_FILE);
That's why I thought this was useless to go with the Web Service, and yes I meant an .ASMX web Service.
I went with the admin of the server and reviewed the event log, there is an error relating a COM+ program that appears every time I run the above method. Sadly, I think the problem has something to do with the server itself.
Do you think I should shut the question?
EDIT
Event viewer logged entry :
The run-time environment has detected an inconsistency in its internal state.
This indicates a potential instability in the process that could be caused by
the custom components running in the COM+ application, the components they
make use of, or other factors. VariantUnmarshal: CoUnmarshalInterface for
IID_IDispatch failure
Server Application ID: {F27C90B8-C40E-4B76-8F01-A8C035EACC08}
Server Application Instance ID:
{79C9FDFC-78AD-461B-95E6-80FF54880317}
Server Application Name: Textml Server
Error Code = 0x800706ba : The RPC server is unavailable.
COM+ Services Internals Information:
File: d:\nt\com\complus\src\comsvcs\ucp\assoc.cpp, Line: 723
Comsvcs.dll file version: ENU 2001.12.4720.3959 shp
For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.

There seems to be some COM+ misconfiguration on your server.
Here are some workarounds by other people running into this problem (Event 4689):
http://www.eventid.net/display.asp?eventid=4689&eventno=3980&source=COM+&phase=1

Related

Deploy a backend application on a Windows Server

I'm making an application in C# with VS 2012 that checks a database every 15 seconds and perform some actions when it finds data. Right now I've created a Console Application so I can debug it easely but during relese this application needs to run in a IIS server.
How can I do that? I've read this question but it looks like some sort of workaround because to run it I need to perform these steps. Right now I'm reading the docs about Windows Service Application, Is this the right way?
EDIT Sorry but I've never used Windows server before, so as people pointed out IIS is only a web server, the thing I need to do is run my application in a Windows Server environment
IIS is a web-server and accordingly it should be used for hosting web applications.
Develop a windows service which does the job of checking the database in intervals and invoke a web service (which you can host in IIS)
If your application is performing some data query and manipulation on the server then I would recommend the approach to host it in a windows service.
Some advantages to this are:
The service will start and run independently of a user logging into the server.
You can configure the service to recover should it experience an exception (ideally not!).
The service will start automatically (if configured) when the server restarts.
You can configure which user group (or user) the service should run under so you have a more granual approach to security.
As it's running as a seperate process, you can monitor its memory and processor utilisation.
Debugging is slightly more cumbersome but not difficult, one approach I've used is to install the service locally, start it and then attach to it via the debugger. This question describes another approach I've also used.

Displaying a stub page while ASP.NET app starts

Can I display a specific page while ASP.NET application is still in the process of initialization?
We've got a huge ASP.NET application that takes about 30 seconds to complete its Application_Start() handler after each redeploy or AppDomain restart. Showing a nice self-reloading "temporarily unavailable" page during that time will greatly improve the experience for first users.
I tried to extract the initializer code into a different thread, but it has a lot of dependencies: the HttpContext, Server and several other classes are unavailable from derived threads. The code becomes intervowen and incomprehendable, so I'm looking for a better solution. Maybe some IIS configuration or extension?
Well, since IIS 7.5 you can use Application Initialization for that (http://www.iis.net/downloads/microsoft/application-initialization) that will make it possible to either show a "splash-Screen" or to just pre-start Application-Pools.
Here is the explanation for IIS8: http://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-application-initialization It will work similar with IIS7.5, but there you have to install the module beforehand.
And here a link taken from the comments: http://blogs.msdn.com/b/abhisk/archive/2013/08/16/configuring-application-initialization.aspx
You could load a static html page or page that is not effected by the system startup, then via ajax poll/check something (value, etc) that will only be available once the application starts, this way you could have an animation or some loading information on the page.
I think you're looking for something that is impossible. So you want to create an Application_Start that takes a long time to finish, and you want your application to be responsive during that time. Application_Start is a synchronous event, meaning that not a single request will begin processing before it completes. It is its job after all.
You have to loosen up your requirements somehow. Here are some ideas.
A new HTTP layer
As I said, you cannot run .NET code in your application before Application_Start finishes. But you can run another, different application.
So let's create another application that faces the clients. A reverse proxy or similar. I'm sure there are reverse proxy implementations out there which allow you to do some scripting and solve the issue. On the other hand, I have myself written a simple reverse proxy in C#. When it received an HTTP request, it created an HttpWebRequest and relayed it to another URL. It supported GET and POST, it is working in production for years now. If you are interested, I may be able to share some details about it.
The only thing you have to solve is how your backend application communicates with the frontend. That's easy, you can use WCF, IPC, create a simple 0-byte marker file somewhere, anything at all. When your Application_Start starts, you can create that 0-byte file, and when it completes, you delete it.
Note that many things happen after you shut down your application, restart it, and before the Application_Start runs. IIS initialization can take a few seconds. So instead of the 0-byte marker file, which only has 2 states (exists/not exists), you can expose a simple WCF service, with named pipes for example. It can have 3 states: doesn't respond at all (the application is stopped), it responds that the application is starting up, or it responds that the application is running. This WCF service has to be self-hosted and run in the background, because IIS won't respond obviously.
HTML/JS magic
It is basically the same idea as above. It is easier because you don't have to set up another application, but less flexible. You have to create an HTML landing page for your application and you have to make sure that users don't bookmark any other page. If you can do that, you are in luck. You can use the ideas from the above solution about how your application can communicate with the outside world while it's starting up. You can not use simple web services hosted in IIS, but you can host your own WCF services without any problems (create your own ServiceHost, etc.). Of course, this self-hosted WCF service won't run at the same host:port as your application. But it's pretty easy to expose a JSON service in WCF.
So, in your HTML landing page, you write some JS AJAX code that queries your self-hosted JSON service. If there is no response, you can tell the user that the application is not running at all. If the service says that it is starting up, you can tell that to the user. If the service says that the application is running, then you redirect your user.
This will not work if your users are browsing your site already when you shut it down. See, that's why you need an entirely new layer.
IIS magic
This is a somewhat uncharted territory for me. In integrated mode, .NET is an integral part of IIS, so I think it's hard to work around it. In classic mode, however, .NET is run as an ISAPI extension. So you can, in theory, write a new ISAPI extension that runs before .NET. The bad news is that it has to be written in C/C++. But it is obvious, because like I said, you cannot run .NET code before Application_Start finishes. But IIS is not dead during that time, so solve it at the IIS level. This can get ugly and I'm only 99% sure that it is actually possible.
Refactoring
The above are all workarounds. You really should refactor your code so that Application_Start finishes quickly. It is not meant to be a heavyweight function. There is already a framework for preloading ASP.NET apps. If you tell us why you need HttpContext and Server in your initialization code, we are here to help you with those problems.

Starting a service programmatically

I'm struggling with starting a service from another application.
Ok, first, that's my starting point:
I got a usual service wrapped into my own class which inherits from ServiceBase.
Furthermore I got a ProjectInstaller instance, which inherits from System.Configuration.Install.Installer and takes care of installing my service on the system in the right way.
it's got these parameters:
serviceInstaller1.ServiceName = "NameOfService";
serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Manual;
serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalService;
This ProjectInstaller output is installed through a usual C# .NET installation project.
The service is shown in the GUI list of services within system control -> administration -> services. But what I'm wondering about is that the service does not appear in the list of services, if I use the cmd.exe and type "net start".
That's waht I have so far.
Now I want to start my service from another application. This application inherits from
ServiceController
If I want to call now the
Start()
method, I get an error telling me that the service could not be opened of the local machine.
I use the same Service Name as stated above. T'm confused about that, because I thought the service is installed correctly through my installer.
Or does my application (and the cmd.exe too) does not have enough rights to access the service?
I found this article on stackoverflow.
I think this answer posted there can be applied here too.
see the link below
ServiceController permissions in Windows 7
I've run into this issue before, and it was permissions-based for me, too. I wish that error message was a little more clear.
I'd recommend taking a look at this SO article: C#.NET: Acquire administrator rights? - it looks like there's a good tutorial about upgrading to administrative rights provided in the answers.

windows service working on windows 7 but not on windows server 2003

Solved the problem see the bottom of my post.
So I have a simple windows service that watches a specific folder and upploads files that come into it to a server using a web service.
It's working fine on my machine using windows 7 but when I try to start it on a windows server 2003, I receive an error: Error 1053: the service did not respond to start or control request in a timely fashion. But I get this message after only a few seconds.
I have created the ServicesPipeTimeout and set it to 60000 milliseconds.
I have tried running it from command line using sc query command and found out that the WIN32_EXIT_CODE is 0, which I think means that the service doesn´t even try to start because it find an error before it starts.
In the event viewer I get errors 7000 and 7009.
I am the Administrator on the windows server.
The only thing I haven´t tried is a hotfix I found from microsoft but I don´t want to use it because as I understand it, it is for when the service actually times out.http://support.microsoft.com/kb/886695
I have tried everything I can think of, is there anything that I am missing?
Gísli
EDIT: Re-installed the .NET framework and now I get a new error, Saying that the service controller can not be found.
EDIT: I setup the service with a setup project, not using the installutil command. This is because I need to get user input during the installation and save that in the registry.
EDIT: I have installed the .NET 4.0 framework, it wasn´t possible to install the service with out doing that.
In addition to what I wrote above I have also tried:
Rebooting.
Re-installing.
I have tried to change the permissions on the files that the service needs to access.
Changing permissions in the registry editor.
Edited the code so that the onStart function only starts one thread.
I think it is some kind of permission problem but I don´t have much experience dealing with Windows server.
Solution:
It turned out to be two seperate problems. The .NET framwork had to be repaired and I had to remove the try/catch clause that I had when starting the service. For some reason (unknown to me) the try catch block did something that made it impossible to start the service in a windows server 2003 but it ran fine on windows 7.
It would be very interesting to know why this is.
Thanks for all the help.
Gísli
Have you installed the right version of .NET Framework on the Server 2003 PC? What comes as standard on Windows 7 will need to be installed manually on an older OS.
You say "I have tried everything I can think of". Please edit the question to show what you have already tried so we don't suggest something you have already done.
EDIT:
Try also the Fusion Log viewer. Set it to log failures then start your service. Hit refresh then see if any errors are logged. Double-click a line for more details.
I'd guess that you installed the .NET 3.5 service using .NET 2.0? InstallUtil will work since the CLR is the same, but the service won't start because of .NET 3.5 dependencies.
See Also:
How to install a Windows service developed in .NET 3.5?
In your OnStart code you could wrap everything in a try-catch block and write the exception message and stack trace to a file using something like:
File.WriteAllText(#"C:\Temp\MyServiceLog.txt", exp.Message + exp.StackTrace);
This will help you analyze the problem. Also, I'm using a very simple way of debugging my services: I'm wrapping them in a WinForms wrapper if the session is interactive. For that, I need the following:
A form that creates an instance of the service class
New methods DoStart and DoStop in my service class, which are public and call the protected OnStart and OnStop methods
New code in above form's OnLoad and OnClose handlers, so the DoStart and DoStop methods of the service instance are called accordingly
Then I add the following code to the Main method in Program.cs:
if (Environment.UserInteractive)
{
Application.Run(new FormServiceHoster());
}
else
{
// ... old code to create service instance.
}
This way you're making the "service" run as an application when you just hit F5 in Visual Studio or double click the EXE in the Explorer. When the service is actually run as a service, the Forms-code is ignored.
Usually you can debug services by attaching to the process, however, that doesn't work for debugging the start and stop code. This method helps a great deal debugging the service start and stop code.
You will need to add references to System.Windows.Forms and System.Drawing manually.
This is the point where I bet you wish you had used some logging package like log4net, which might help tell how far your program gets.
Is it possible that the code in the OnStart event is actually taking longer than you expect. If so, you could move that code to a thread, so that the OnStart event finishes (and so Windows reckons the service has started) while your thread continues working.
Are you running the service as admin? If so, that usually rules out permissions issues. (If it still goes wrong, it will rule out the KB 886695 issue as that seems to only apply to local system).
Since you are using .NET 4.0 are you sure that either, the full version is installed, rather than the Client Profile, or that your application works with the client profile?

WebService: Difference between my pc and server

I have a bug where special characters (danish 'ø' in this case) are shown correctly when running locally, but wrong when the code runs on a server (I get a pipe '|'). I was trying to solve this today, but I did not have access to the server, other than updating the code files. I will limited access monday, so I can at least write intermediate results to a log file, but to be prepared I thought I'd ask for suggestions here.
Program flow:
A C# test calls my own web service via a WebRequest.
This web service calls an external web service via another web request.
When running my own web service locally I get correct results returned from the external web service.
When deploying the code to the server the external web service returns an error; it didn't find the word I was searching for. Except that I entered 'Bøssemagergade', but the word it complains about is returned as 'B|ssemagergade'. What can cause this difference? AFAIK the server runs with the exact same regional settings as my local machine.
I'm sure this is common stuff, but I haven't been doing web services before (I do feel at home with C#/.NET though, and know about encodings etc.).
Thanks!
You need to check your data at every stage in the process. Make sure you understand which encoding you're using (try to avoid using Encoding.Default) and verify the binary data going across the wire with something like WireShark.
See my debugging unicode problems article for further information.

Categories