If this works in Visual Studio, it is likely because the process (WebDev.WebServer.exe) is running as YOU, and you probably have Administrator privileges. When you run in IIS, it will be run in w3wp.exe as whomever is configured as the application pool
identity (likely Network Service or "ApplicationPoolIdentity", which have limited privileges). It's probably not a code issue, but you probably need to look into what permissions are needed to have this work. You could test by impersonating in the web.config.
If you add <identity impersonate="true" userName="{YourAcct}" password="{YourPassword}" /> does it work in IIS?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
//-----------------------------
using System.Runtime.InteropServices;
namespace WebApplication1
{
/// <summary>
/// WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// ASP.NET AJAX를 사용하여 스크립트에서 이 웹 서비스를 호출하려면 다음 줄의 주석 처리를 제거합니다.
// [System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
public enum FileMapAccess
{
FILE_MAP_COPY = 0x0001,
FILE_MAP_WRITE = 0x0002,
FILE_MAP_READ = 0x0004,
FILE_MAP_ALL_ACCESS = 0x000F001F
}
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr OpenFileMapping(
FileMapAccess dwDesiredAccess, // Access mode
bool bInheritHandle, // Inherit flag
string lpName // File mapping object name
);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool CloseHandle(IntPtr hHandle);
[WebMethod]
//**********************************************************************************************
public bool CreateMapView()
//**********************************************************************************************
{
try
{
//----------------------------------------------------------------------------------------
IntPtr hMapFile = OpenFileMapping( // Open the named file mapping.
FileMapAccess.FILE_MAP_ALL_ACCESS,
false,
@"Global\" + "NameForTest");
if (hMapFile == IntPtr.Zero)
{
Console.WriteLine("Err: cannot open the shared memory!!!");
return false;
}
else
{
Console.WriteLine("succeed in opening the shared memory!!!");
return true;
}
}
//----------------------------------------------------------------------------------------
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
}
}
FileMapping may be profile specific. In IIS, the process running your code will be a generic user depending on the OS. I would configure the application pool to run as your account and see if that makes any difference. If you still have issues, I would
run
Process Monitor while reproducing the issue to see if it can determine some issue.
JJGJJG72
0 Points
7 Posts
Q1. on webservice in IIS, VS2010, I can't get the return-value of funtion on DLL ...
Oct 30, 2012 12:13 PM|LINK
even though I'm foreigner and my english is not good, I'll do my best to explain about my situation to solve.
I installed that
1.vs2010
2.windows7
3.IIS 7.0
4.Framework 4.0 for IIS.
I selected the tab [WEB] on the protperty of my project.
1. after I select the radiobutton [Use visual studio development Server], I ran my webservice.
I could get the correct return-value of the funtion on DLL(for example, the value is "1")
2. but when I ran my webservice after selecting the radiobutton [Use Local IIS Web server],
I could not get the correct return-value of the funtion on DLL(for example, the value is "")
,and at the same time, I tried to get the value of funtion "Helloworld" that is sample funtion and isn't on my DLL for Webservice testing.
the sample funtion "HelloWorld" of webservice is running well to get the correct value "Helloworld".
????
please, show me the way to sovle this problem...--;
Haixia Xie -...
Contributor
3022 Points
294 Posts
Microsoft
Re: Q1. on webservice in IIS, VS2010, I can't get the return-value of funtion on DLL ...
Oct 31, 2012 10:35 AM|LINK
Hi JJGJJG72,
To troubleshoot the issue, more information is needed, you can provide a screenshot here and you can try to inspect the messages with fiddler.
Best Regards,
Feedback to us
Develop and promote your apps in Windows Store
JJGJJG72
0 Points
7 Posts
Re: Q1. on webservice in IIS, VS2010, I can't get the return-value of funtion on DLL ...
Nov 01, 2012 02:00 AM|LINK
PICTURE No1.: the project property screen in VS2010
-----------------------------------------------------
I used the sharedmemory on my webservice project like following.
.
IntPtr hMapFile = OpenFileMapping( // Open the named file mapping. FileMapAccess.FILE_MAP_ALL_ACCESS, false, str_맵파일명);
-----------------------------------------------------
CASE 1:
after I select the radiobutton [Use visual studio development Server] on picture No.1, I ran the my webservice.
I could get the correct return-value of hMapFile from the "OpenFileMapping" that is "1316"
CASE 2:
but when I ran my webservice after selecting the radiobutton [Use Local IIS Web server] on picture No.1,
I could get the incorrect return-value of hMapFile that is "0"
.
Q1. Could I get the samplecode in C# to solve this trouble??(CreateFileMapping, OpenFileMapping with SECURITY code)
or How do I change the setting in IIS 7.0.
cts-mgraham
Contributor
3318 Points
642 Posts
Microsoft
Re: Q1. on webservice in IIS, VS2010, I can't get the return-value of funtion on DLL ...
Nov 07, 2012 07:05 PM|LINK
If this works in Visual Studio, it is likely because the process (WebDev.WebServer.exe) is running as YOU, and you probably have Administrator privileges. When you run in IIS, it will be run in w3wp.exe as whomever is configured as the application pool identity (likely Network Service or "ApplicationPoolIdentity", which have limited privileges). It's probably not a code issue, but you probably need to look into what permissions are needed to have this work. You could test by impersonating in the web.config. If you add <identity impersonate="true" userName="{YourAcct}" password="{YourPassword}" /> does it work in IIS?
JJGJJG72
0 Points
7 Posts
Re: Q1. on webservice in IIS, VS2010, I can't get the return-value of funtion on DLL ...
Nov 09, 2012 12:21 AM|LINK
thank you for your kind reply.. but...
I can't still get the correct return-vaulue of funtion in only IIS ...
below is the code on the <system.web>of "web.config*" file that is used by me.
------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="Register.aspx">
<system.web>
<identity impersonate="true" userName="jjg" password="1234" />
<authorization> <allow users="*"/> </authorization> </system.web> </location>
<system.web>
<identity impersonate="true" userName="jjg" password="1234" />
<authorization> <deny users="?"/> </authorization> </system.web>
</configuration>
-----------------------------------------------------
or
------------------------------------
<system.web>
<trust level="Full"/>
<identity impersonate="true" userName="jjg" password="1234" />
</system.web>
-----------------------------------------------------
the "userName","password" which are used in web.confg is my account of windows for login that has the property for administrator.
I found two web.config in the project.
one is "web.config", another is "web.config*". I used "web.config*".
JJGJJG72
0 Points
7 Posts
Re: Q1. on webservice in IIS, VS2010, I can't get the return-value of funtion on DLL ...
Nov 13, 2012 04:21 AM|LINK
I made the sample code to reappearance this trouble that is same with my situation.
you can experience this trouble, when you copy and paste in the VS2010.
the first code is for winform with only one button object in VS2010 to create the sharedmemory.
the second cdoe is for webservice in VS2010 to open the sharedmemory.
--------------------------------------------------------------------
I can't still get the correct return-vaulue of the funtion in only IIS ...
Can I get the real help from MS or ETC with this samplecode....??
--------------------------------------------------------------------------------
1. the below is the perfect code for winform to create the sharedmemory and reappear the trouble....
--------------------------------------------------------------------
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; //---------------------------------------------------------------------------------------- using System.Runtime.InteropServices; using System.Security; using System.Windows.Forms; using System.Collections; //------------------------------------------------------- using DWORD = System.UInt32; namespace WebTest { public partial class Form1 : Form { const uint BUFFER_SIZE = 256; public const int INVALID_HANDLE_VALUE = -1; //---------------------------------------------------------------------------------------- public enum FileProtection : uint { PAGE_NOACCESS = 0x01, PAGE_READONLY = 0x02, PAGE_READWRITE = 0x04, PAGE_WRITECOPY = 0x08, PAGE_EXECUTE = 0x10, PAGE_EXECUTE_READ = 0x20, PAGE_EXECUTE_READWRITE = 0x40, PAGE_EXECUTE_WRITECOPY = 0x80, PAGE_GUARD = 0x100, PAGE_NOCACHE = 0x200, PAGE_WRITECOMBINE = 0x400, SEC_FILE = 0x800000, SEC_IMAGE = 0x1000000, SEC_RESERVE = 0x4000000, SEC_COMMIT = 0x8000000, SEC_NOCACHE = 0x10000000 } //---------------------------------------------------------------------------------------- [DllImport("Kernel32.dll", SetLastError = true)] public static extern IntPtr CreateFileMapping( IntPtr hFile, // Handle to the file IntPtr lpAttributes, // Security Attributes FileProtection flProtect, // File protection uint dwMaximumSizeHigh, // High-order DWORD of size uint dwMaximumSizeLow, // Low-order DWORD of size string lpName // File mapping object name ); [StructLayout(LayoutKind.Sequential)] public struct SECURITY_ATTRIBUTES { public DWORD nLength; public IntPtr lpSecurityDescriptor; [MarshalAs(UnmanagedType.Bool)] public bool bInheritHandle; } public enum FileMapAccess { FILE_MAP_COPY = 0x0001, FILE_MAP_WRITE = 0x0002, FILE_MAP_READ = 0x0004, FILE_MAP_ALL_ACCESS = 0x000F001F } [DllImport("Kernel32.dll", SetLastError = true)] public static extern IntPtr MapViewOfFile( IntPtr hFileMappingObject, // Handle to the file mapping object FileMapAccess dwDesiredAccess, // Desired access to file mapping object uint dwFileOffsetHigh, // High-order DWORD of file offset uint dwFileOffsetLow, // Low-order DWORD of file offset uint dwNumberOfBytesToMap // Number of bytes map to the view ); [DllImport("kernel32.dll", SetLastError = true)] public static extern bool CloseHandle(IntPtr hHandle); //************************************************************************************ public Form1() //************************************************************************************ { InitializeComponent(); } //************************************************************************************ private void button1_Click(object sender, EventArgs e) //************************************************************************************ { try { //---------------------------------------------------------------------------------------- SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES(); sa.nLength = (DWORD)System.Runtime.InteropServices.Marshal.SizeOf(sa); sa.lpSecurityDescriptor = IntPtr.Zero; sa.bInheritHandle = true; IntPtr attr = Marshal.AllocHGlobal(Marshal.SizeOf(sa)); Marshal.StructureToPtr(sa, attr, true); //string strMapFileName = "Local\\HelloWorld"; IntPtr hMapFile = CreateFileMapping( (IntPtr)INVALID_HANDLE_VALUE, attr, FileProtection.PAGE_READWRITE, 0, BUFFER_SIZE, @"Global\" + "NameForTest"); //---------------------------------------------------------------------------------------- IntPtr pBuf = MapViewOfFile( hMapFile, FileMapAccess.FILE_MAP_ALL_ACCESS, 0, 0, BUFFER_SIZE); if (pBuf == IntPtr.Zero) { MessageBox.Show(string.Format("Err:cannot create the sharedmemory!!!")); CloseHandle(hMapFile); return; } else { MessageBox.Show(string.Format("Succeed in create the sharedmemory!!!")); } //---------------------------------------------------------------------------------------- } //---------------------------------------------------------------------------------------- catch (Exception ex) { MessageBox.Show(string.Format( ex.Message)); } } } }------------------------------------------
2. the below is code for webservice to open the shared memory.
-------------------------------------------------------------------------
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; //----------------------------- using System.Runtime.InteropServices; namespace WebApplication1 { /// <summary> /// WebService1/// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // ASP.NET AJAX를 사용하여 스크립트에서 이 웹 서비스를 호출하려면 다음 줄의 주석 처리를 제거합니다. // [System.Web.Script.Services.ScriptService] public class WebService1 : System.Web.Services.WebService { [WebMethod] public string HelloWorld() { return "Hello World"; } public enum FileMapAccess { FILE_MAP_COPY = 0x0001, FILE_MAP_WRITE = 0x0002, FILE_MAP_READ = 0x0004, FILE_MAP_ALL_ACCESS = 0x000F001F } [DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr OpenFileMapping( FileMapAccess dwDesiredAccess, // Access mode bool bInheritHandle, // Inherit flag string lpName // File mapping object name ); [DllImport("kernel32.dll", SetLastError = true)] public static extern bool CloseHandle(IntPtr hHandle); [WebMethod] //********************************************************************************************** public bool CreateMapView() //********************************************************************************************** { try { //---------------------------------------------------------------------------------------- IntPtr hMapFile = OpenFileMapping( // Open the named file mapping. FileMapAccess.FILE_MAP_ALL_ACCESS, false, @"Global\" + "NameForTest"); if (hMapFile == IntPtr.Zero) { Console.WriteLine("Err: cannot open the shared memory!!!"); return false; } else { Console.WriteLine("succeed in opening the shared memory!!!"); return true; } } //---------------------------------------------------------------------------------------- catch (Exception ex) { Console.WriteLine(ex.Message); return false; } } } }cts-mgraham
Contributor
3318 Points
642 Posts
Microsoft
Re: Q1. on webservice in IIS, VS2010, I can't get the return-value of funtion on DLL ...
Nov 28, 2012 11:33 AM|LINK
FileMapping may be profile specific. In IIS, the process running your code will be a generic user depending on the OS. I would configure the application pool to run as your account and see if that makes any difference. If you still have issues, I would run Process Monitor while reproducing the issue to see if it can determine some issue.