.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Windows Service crashing on call to unmanaged code, even though console app version works

Posted By:      Posted Date: October 12, 2010    Points: 0   Category :.NET Framework

I have a C# program that at some point calls 2 functions from an unmanaged dll using p/invoke.  Everything works fine when I'm running in a console app.  When I compile the same program as a windows service and run it, it crashes.  The console app and service should be identical as far as my code is concerned... all either program does is create an object from another assembly of mine and run a Start() method on it.

I have used VS2010 to debug the managed and unmanaged code, and when I step through the Console app everything looks great.  When I attach the debugger to the service, i can step through the first function in the unmanaged code, control returns to the managed code, and then later when it comes to the point where it calls the second unmanaged function, the process terminates immediately before the debugger steps into the first line of unmanaged code.  There are no exceptions that I can see, and the only thing written to the event log is the generic "service terminated unexpectedly" message.  Running "sc query" on the command line lets me know the win32_exit_code is 1067.

Im running everything in .net 4, on winxp 32bit.  The serivce is running as Local System ideally, but the same behavior exists when I run it under my user account. 

View Complete Post

More Related Resource Links

C++ and ATL: Use ATL Server Classes to Expose Your Unmanaged C++ Code as an XML Web Service


Throughout this issue, you'll read all about the promise of Web Services and how the .NET Framework enables Web Service development. Many people will also be building their Web Services atop C++ code and frameworks like ATL Server, particularly when performance is paramount. In this article, the authors show how fully functional Web Services are built using ATL Server and Visual Studio .NET. Beginning with unmanaged C++ classes, they add ATL attributes that make the code work over HTTP.

Kirk Fertitta and Chris Sells

MSDN Magazine December 2002

Unable to call an asmx web service using windows authentication from a Service workflow

Hello, I need to use an existing asmx service from inside my service workflow and I am unable to call it. This asmx service is hosted in a web application with iis set to windows authentication, anonymous is not allowed. I need to send the authentication, only way seems too be using transport for basicHttpBindings. Every time I try to call the service I get an error saying that there is nothing listening to the url of the service generated automatically by VS when I added the Service Reference ? my web config <configuration> <configSections> </configSections> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <protocolMapping> <add scheme="http" binding="wsHttpBinding" bindingConfiguration="WindowsCreds" /> </protocolMapping> <bindings> <basicHttpBinding> <binding name="UtilitiesSoap" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"

Why windows service Looks for "Classlibrary2.resources Version=" assembly in resolver eve

In a simple Windows Service project, I have got below code. namespace WindowsService1 {     static class Program     {         /// <summary>         /// The main entry point for the application.         /// </summary>         static void Main()         {             System.Diagnostics.Debugger.Launch();             AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);             ClassLibrary2.Class1.Hello();         }         private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)         {             return null;         }     } } Here "ClassLibrary2" is a simple class library project with couple resources and single class. No other settings are set. After installing WindowsService1, on starting the s

How to Find out Windows service application path from Code ?

Dear frnds, Could you please help me to find out the path of  windows serivce exe ( application path ) from code?   Regards. Sajid P K  

TCP Error Code 10060 when attempting to access WCF Service hosted by WIndows Service from client run


Hello all,

We have a Framework 3.5 WCF Service which is in turn hosted in a Windows Service using Net.Tcp Binding. SvcUtil is used to generate the proxy which is used instead of a service reference in the client code. We are also using Tcp Port Sharing. The endpoint address is net.tcp://HostMachineName/MyServicePath. The service logs to the Event log and everything works perfectly on the same machine.

When attempting to run the client from a different machine we are getting TCP Error Code 10060 errors. Below is the error message:

System.ServiceModel.EndpointNotFoundException: Could not connect to net.tcp://HostMachineName/MyServicePath. The connection attempt lasted for a time span of 00:00:20.8592415. TCP error code 10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 111.22.333.444:808.  ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 111.22.333.444:808... The IP Address displayed was the correct IP Address for the HostComputerName.

Has anyone encountered this problem? Also, client specs say no config files, so anything that wo

Creating a service host in a console app works fine in Debud but not opening exe


I have a Simple console app that starts to host my  wcf service and it works great when I'm debugging but when i run the exe it doesnt start the WCFSvcHost from my tray like i do when i dubug. Any ideas..

This is my host:

class Host
    static void Main(string[] args)
      ServiceHost host = new ServiceHost(typeof(EvalService));


      Console.WriteLine("Eval Service is up and running with the following endpoints:\n");
      foreach (ServiceEndpoint se in host.Description.Endpoints)


Create an exchange interface to call a Windows Service with WCF


I'm develpong an application that consists on a Client that communicates with a Windows Service via WCF.
I have three projects defined: MyClient, MyService, MyExchangeClasses

The first two are easy to understand, client and server. The MyExchangeClasses project contains the interface for MyService remote function calls and contains the implementation of those classes that are passed via parameter o are returned by the remote functions that implement the interface I've already mentioned.

For example I have one remote funciton defined in the interface like this:

public interface IService1
   IEnumerable<MyObject> GetAllMyObjects();

And MyObject is defined like this:

public class MyObject    
    public String Name { get; set; }

So in order to make it work MyExchangeClasses needs to be referenced in both MyClient and MyService classes.

Not able to get current windows user in RS2005 (but same code works for RS2000)


We use the following custom code (checkGroupMembership.dll) to get identity of the current windows user and then check if the user is part of a certain group (roleName in code below).  

SecurityPermission perm = new SecurityPermission(SecurityPermissionFlag.ControlPrincipal);
WindowsIdentity wi = WindowsIdentity.GetCurrent();
WindowsPrincipal cPrincipal = new WindowsPrincipal(wi);    
isMember = cPrincipal.IsInRole(roleName);

The code above behaves differently for RS2000 vs. RS2005. Both RS2000 and RS2005 are installed on same server. If I use the following code to check the WindowsPrincipal name, I get the expected result (my windows login ID) when called from a report in RS2000 but for RS2005 I get the user id of reporting services.


I have checked rssrvpolicy.config (for both RS2000 and RS2005) and it has the same permission for checkGroupMembership.dll.

Any suggestions on why the same code will get different WindowsIdentity? Where I should look next? Any help would be greatly appreciated.


How can I call the windows authentication window from C# code?





I have a windows application which tries to get information from the internet. But the connection to the internet can only be established through a proxy server.

Normally, the users who use the application log in with their credentials and that should automatically connect to the proxy server. But, for example, when you try opening Internet Explorer which is set up to use a proxy, it pops up the log-in window to authenticate to the proxy server, in case it is not saved.

My problem is, if it is saved, I can take the default credentials and proxy server using

System.Net.WebProxy.GetDefaultProxy(); (I know this is deprecated, but it works for me. I would appreciate a more elegant solution).



But, in case it is not saved, I want to pop-up the windows authentication window like the IE does. Is it possible to that? If yes, I would appreciate a little help, otherwise I have to write my own authentication window.

Please respond asap.

Thanks in advance.

Unable to call WCF Service (svc) from .NET Windows Service



 I have an odd problem. I created a windows service and in it I created a reference to my wcf service which is hosted in IIS. I generated the proxyclient for async operations.

When I tried calling it in my development machine it didnt throw any error but it also didnt invoke the wcf service. After a lot of permutations I changed the user account of the windows service to "Network Service" instead of "Local System" and it started working.


Now i have deployed the same to Windows 2003 server. I have again landed up with the same issue. I did change it to Network account but no use. I am not too sure whats the problem as no errors are being thrown nor is it showing any errors in debug mode.

Any thoughts on this pls?

Thanks & Regards



Web service call fails on Windows 7


I have a Windows application written in C# using .NET 2.0 and Visual Studio 2005. I develop on a Windows XP machine. The application makes web service calls over SSL. To support SSL, I have to install WSE 3.0 on the development machine.

When I run my app on an XP machine it works perfectly and makes web service calls to an SSL enabled web service after I set the following registry entry to a non-zero value:

DWORD Value = zero Value = nonzero
UseScsvForTls  Client sends Renego Info extension for TLS  protocol  Client sends SCSV for TLS  protocol



The problem occurs when I run the app on a Windows 7 machine. The web service call fails with the following error:


The underlying connection was closed: An unexpected error occurred on a send.-   at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)

   at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)

   at Mic

Connection times out when WCF client tries to call WCF service, both in Windows Forms apps



The exception message is: Could not connect to TCP error code 10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

What I am trying to do: a WCF service is self hosted in a Windows Forms application. The WCF client is in another Windows Forms application. Eventually, the client is supposed to run on a computer somewhere out there on the Internet and send messages to the server which is running on my home computer. This is my first attempt at making a remote WCF call.

I have success when server and client either run on the same computer, or are running on different computers attached to my little in-home LAN. When I try to route the client's request via Internet (in preparation for having the client reside out there somewhere) I get the exception reproduced in the first paragraph above after waiting for about 20 seconds.

OS is WinXP Pro with SP3. Using Visual Studio 2008, Visual Basic. is the IP currently assigned to me by Comcast (I watch carefully to see when it changes; also, I altered it for purposes of asking this question).


How to call Windows service from another Application



I have Created one  Windows Service using ATL and COM,How to call this Service from My application which is also in ATL and COM.

Please help me.

trying to call a web service with credentials gives me 505: HTTP Version Not Supported


I am trying to call an webservice from .net code.  I believe the webservice is java based.  If I visit the WSDL, I see this "WSDL created by Apache Axis version: 1.2".


When I call the web service with no credentials, I get the error 401: Unauthorized.

When I call the web service with credentials I get the error 505: HTTP Version Not Supported

401 Error:

SearchService svc = new global::Search.SearchService();
svc.Url = svcAddress;
SearchRequest req = new SearchRequest();
SearchResponse resp = svc.search(req);
 //The request failed with HTTP status 401: Unauthorized.

505 Error:

SearchService svc = new global::Search.SearchService();
svc.Url = svcAddress;
SearchRequest req = new SearchRequest();
svc.Credentials = new System.Net.NetworkCredential("user", "pass");
SearchResponse resp = svc.search(req);
//The request failed with HTTP status 505: HTTP Version Not Supported.


Also I have tried adding all of the following:

            svc.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Default;

            svc.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Soap

svcutil ( wrong code) and add service reference (works smoothly)


Hi all,

I have a web service at java and I want to consume it with wcf. When I use add service reference to create the proxy everything works ok! When I tried to generate the proxy with svcutil it's generates me two files (*.cs and app.config) which I think is all I need. But nothing works, no errors but when I try to call the services I get nothing!!! But in the case you can't use add service reference (like an authenticated scenario which is the next step for me) what can I do? Why is this happening?Can someone help me?


RESTful service call results in status code 409 - why?


My RESTful WCF service has methods to retrieve and update an object.  The retrieval works just fine but the update (or PUT) doesn't.

Here's the service interface and implementation:


    public interface ICandidate
        Common.RestResponse<Person> GetPersonByIndex(string index);

        void UpdatePerson(string id, Person person);
    public class Candidate : ICandidate
        [WebGet(UriTemplate = "/{index}",
                RequestFormat = WebMessageFormat.Json,
                ResponseFormat = WebMessageFormat.Json)]
        public Common.RestResponse GetPersonByIndex(string index)
            Common.RestResponse result = new TWA.Common.RestResponse();

            int Index = 0;
            if (Int32.TryParse(index, out Index)) 
                List list = PersonService.GetPersonList(true, true, true);
                if (list.Count > Index)
                    result.Success = true;
                    result.Count = list.Count;
                    result.Data = list[Index];

Web service call fails on windows 7 with LSP



I am facing connectivity issue from windows 7 client developed in dotnet 2.0 to a webservice which is developed in dotnet 2.0 and hosted in windows 2003 server. The error I am getting is,

"Error Message: Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section."

For a specific functionality, the client has to function with Layered Service Provider (LSP)
This LSP will be automatically installed in the windows 7 client while installing the Agent kit. I suspect the issue is because of LSP .


Client (Windows 7)   :

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend