MSDN > フォーラム ホーム > Visual C++ Language > c# web service having problems with native C++ ordinals
質問する質問する
 

質問c# web service having problems with native C++ ordinals

  • 2009年10月24日 1:19hegsie ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Hi,
    I have a rather strange problem in that I have a c# web service which in turn compiles in some C++/CLI dll's which then links to some ancient native C++ code that we have.  Recently I added some new code to one of the native dll's and since then I haven't been able to bring the web service up in IIS as we have done in the past.  We also have some c# windows services that are architected in a similar way on top of the same C++/CLI dll's and native code and they run fine.

    Now I've had a look at the ordinals in the old version of the native C++ dll that I changed and the _declspec(export) declaration has added the new function into the middle of the ordinal list of the new version of the dll, now I've rebuilt the entire system from end to end and double checked the references to make sure there aren't any bad linkages.  Does anyone know what is going on with IIS and checking C++ ordinals?  I've replaced the new DLL with a copy of the old DLL and then the web service in IIS is fine.  Is there a way to manage how _declspec(export) inserts new ordinals into the that list?

    Just to elaborate the linkage is..

    webservice.csproj
    webservice.asmx
    webservice.dll links to 

    (C++/CLI) Connector.vcproj
    connector.dll links to 

    (native C++ DLL) myNativeProject.vcproj
    ancientcode.dll

    So I added a new function to ancientcode.dll and it got added in the middle of the ordinal list and when I recompile all the projects and try to run the webservice.asmx it fails...


    Cheers
    • 編集済みhegsie 2009年10月24日 12:50More Explanation
    •  

すべての返信

  • 2009年10月26日 8:14Rong-Chun ZhangMSFT, モデレータユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Hello hegsie,

    Thanks for your post.

    When the webservice.asmx fails, did you get any error message? Please also collect the recent log files in \System32\LogFiles\W3SVC[n]\ directory (n here is the Site ID which can be viewed in the right panel by clicking Web Sites folder in IIS). If you are using IIS7, the log file can be found under inetpub\log\logfiles\w3svc[n].

    Thanks,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • 2009年10月26日 11:40hegsie ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     コードあり
    Hi,
    The actual error you see in the web browser is below...

    Server Error in '/DLMessenger' Application.

    Configuration Error

    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: Invalid access to memory location. (Exception from HRESULT: 0x800703E6)

    Source Error:

    Line 57:                 <add assembly="System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    Line 58:                 <add assembly="System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    Line 59:                 <add assembly="*"/>
    
    
    
    Line 60:                 <add assembly="System.Runtime.Serialization, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"/>
    Line 61:                 <add assembly="System.IdentityModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"/>

    Source File: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\web.config    Line: 59


    Version Information:  Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053

    The is also the following in the eventvwr log...


    Event Type:    Warning
    Event Source:    ASP.NET 2.0.50727.0
    Event Category:    Web Event
    Event ID:    1310
    Date:        10/26/2009
    Time:        7:33:57 AM
    User:        N/A
    Computer:    NYAVINTDCWEB1
    Description:
    Event code: 3008
    Event message: A configuration error has occurred.
    Event time: 10/26/2009 7:33:57 AM
    Event time (UTC): 10/26/2009 11:33:57 AM
    Event ID: 03d69fd3b3bf48c9bd55bb20e44ea150
    Event sequence: 1
    Event occurrence: 1
    Event detail code: 0
     
    Application information:
        Application domain: /LM/W3SVC/2/Root/DLMessenger-1-129010304370525072
        Trust level: Full
        Application Virtual Path: /DLMessenger
        Application Path: D:\Program Files\Dealogic\Datacenter\dc\websites\dlmessenger\
        Machine name: NYAVINTDCWEB1
     
    Process information:
        Process ID: 5276
        Process name: w3wp.exe
        Account name: NT AUTHORITY\NETWORK SERVICE
     
    Exception information:
        Exception type: HttpException
        Exception message: Invalid access to memory location. (Exception from HRESULT: 0x800703E6) (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\web.config line 59)
     
    Request information:
        Request URL: http://129.47.3.34/DLMessenger/Messenger.asmx
        Request path: /DLMessenger/Messenger.asmx
        User host address: 129.47.3.34
        User: 
        Is authenticated: False
        Authentication Type: 
        Thread account name: NT AUTHORITY\NETWORK SERVICE
     
    Thread information:
        Thread ID: 1
        Thread account name: NT AUTHORITY\NETWORK SERVICE
        Is impersonating: False
        Stack trace:    at System.Web.Compilation.BuildManager.ReportTopLevelCompilationException()
       at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
       at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters)
     
     
    Custom event details:

    For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.


    And the IIS logs have the following...

    #Software: Microsoft Internet Information Services 6.0
    #Version: 1.0
    #Date: 2009-10-26 11:33:57
    #Fields: date time s-sitename s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status
    2009-10-26 11:33:57 W3SVC2 129.47.3.34 GET /DLMessenger/Messenger.asmx - 80 - 129.47.3.34 Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+5.2;+.NET+CLR+1.1.4322;+.NET+CLR+2.0.50727;+.NET+CLR+3.0.4506.2152;+.NET+CLR+3.5.30729) 500 0 0

    Regards
    Hegs
  • 2009年10月29日 10:10Rong-Chun ZhangMSFT, モデレータユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Hello Hegs,

    Thanks for you effort.

    From the IIS log, the problem comes from the server side. Please try to move the line <add assembly="*"/> to the last line(assemblies element) of the webconfig.

    http://msdn.microsoft.com/en-us/library/37e2zyhb.aspx

    Please also check if you have the permission to access the new dll file( by default nerworkservice account).

    If these things do not help, we need to debug the web service to find where the error actually happened, we can use WinDBG to attach to the w3wp.exe.

    http://weblogs.asp.net/owscott/archive/2004/09/21/Which-w3wp.exe-process-belongs-to-which-App-Pool-in-IIS6.aspx

    Thanks,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • 2009年10月30日 10:18hegsie ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     コードあり
    Hi Rong-Chun,
    So I finally figured out what was causing the issue however I'm a little confused why this would cause this problem. 

    The ancientcode.dll that I spoke about above is the problem but it had nothing to do with the ordinals as I first thought, the ancientCode.dll or Logging.DLL as its actually known contains two singletons one for performing the logging to file and a second for managing access to the ini file. 

    Below is the broken file...

    #include "stdafx.h"
    #include "ConfigFile.h"
    
    #include <fstream>
    #include <set>
    
    #include "LogMgr.h"
    
    std::string trim(std::string const& source, char const* delims = " \t\r\n") {
    	std::string result(source);
    	std::string::size_type index = result.find_last_not_of(delims);
    	if(index != std::string::npos)
    		result.erase(++index);
    
    	index = result.find_first_not_of(delims);
    	if(index != std::string::npos)
    		result.erase(0, index);
    	else
    		result.erase();
    	return result;
    }
    
    ConfigFile::ConfigFile(std::string const& configFile) : _filename(configFile)
    {
    	std::ifstream file(_filename.c_str());
    
    	if (!file.good())
    		throw std::string(_filename + " does not exist ");
    
    	std::string line;
    	std::string name;
    	std::string value;
    	std::string inSection;
    	int posEqual;
    	while (std::getline(file,line)) {
    
    		if (! line.length()) continue;
    
    		if (line[0] == '#') continue;
    		if (line[0] == ';') continue;
    
    		if (line[0] == '[') {
    			inSection=trim(line.substr(1,line.find(']')-1));
    			continue;
    		}
    
    		posEqual=line.find('=');
    		name  = trim(line.substr(0,posEqual));
    		value = trim(line.substr(posEqual+1));
    
    		content_[inSection+'/'+name]=Chameleon(value);
    	}
    }
    
    ConfigFile::~ConfigFile()
    {
    	std::ofstream outfile (_filename.c_str());
    
    	// get all the sections
    	std::set<std::string> sections;
    	for (std::map<std::string,Chameleon>::iterator it = content_.begin();it != content_.end();++it)
    		sections.insert(it->first.substr(0,it->first.find('/')));
    
    	for (std::set<std::string>::iterator it = sections.begin();it != sections.end();++it)
    	{
    		outfile << "[" << (*it) << "]\n";
    		for (std::map<std::string,Chameleon>::iterator it2 = content_.begin();it2 != content_.end();++it2)
    		{
    			size_t found = it2->first.find((*it));
    			if (found != std::string::npos)
    			{
    				size_t slash = it2->first.find('/');
    				outfile << it2->first.substr(slash+1,it2->first.size()) << "=" << std::string(it2->second) << "\n";
    			}
    		}
    		outfile << "\n";
    	}	
    
    	outfile.close();
    }
    
    Chameleon const& ConfigFile::Value(std::string const& section, std::string const& entry) const {
    
    	std::map<std::string,Chameleon>::const_iterator ci = content_.find(section + '/' + entry);
    
    	if (ci == content_.end()) throw "does not exist";
    
    	return ci->second;
    }
    
    Chameleon const& ConfigFile::Value(std::string const& section, std::string const& entry, double value) {
    	try {
    		return Value(section, entry);
    	} catch(const char *) {
    		return content_.insert(std::make_pair(section+'/'+entry, Chameleon(value))).first->second;
    	}
    }
    
    Chameleon const& ConfigFile::Value(std::string const& section, std::string const& entry, std::string const& value) {
    	try {
    		return Value(section, entry);
    	} catch(const char *) {
    		return content_.insert(std::make_pair(section+'/'+entry, Chameleon(value))).first->second;
    	}
    }
    
    static ConfigFile* config = NULL;
    
    DllExport bool OpenConfigFile(std::string const& aFilename)
    {
    	if (config == NULL)
    	{
    		try
    		{
    			config = new ConfigFile(aFilename);	
    		}
    		catch (std::string e)
    		{
    			LOG_MSG(LEVEL_CRITICAL, e.c_str());
    		}
    		
    	}
    	return true;
    }
    
    DllExport void CloseConfigFile()
    {
    	if (config)
    	{
    		// Destructors NEVER throw exceptions
    		delete(config);
    		config = NULL;			
    	}
    }
    
    DllExport double GetDoubleConfigValue(std::string const& aSection, std::string const& aEntry)
    {
    	return config->Value(aSection,aEntry);
    }
    
    DllExport std::string GetStringConfigValue(std::string const& aSection, std::string const& aEntry)
    {
    	return config->Value(aSection,aEntry);
    }
    
    DllExport void SetStringConfigValue(std::string const& aSection, std::string const& aEntry, std::string const& aValue)
    {
    	config->Value(aSection,aEntry,aValue);
    }
    
    
    There are actually two issues with this file for the asmx service, first the ConfigFile class has a destructor, which for some reason causes the 'invalid access to memory location' and second the calling into the other singleton via the..

    LOG_MSG(LEVEL_CRITICAL, e.c_str());<br/>
    
    
    call also causes it..

    The only Q I have now is why?
  • 2009年11月4日 12:21Rong-Chun ZhangMSFT, モデレータユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Hello

    It's hard to guess why the error is thrown, we need to debug the web service to find which line the error actually happened, we can use WinDBG or Visual Studio to attach to the w3wp.exe.

    Thanks,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.