Click here to Skip to main content
15,917,971 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is the scenario:

I have built a wcf rest 4.0 using VS 2010 online template 40(cs).
I have a web GET method defined which calls a function in native C dll.

[DllImport("DLookupDLL.dll", EntryPoint = "GetDistInfo")]
public static extern bool GetDistInfo(StringBuilder distfile, int input, IntPtr distInfo );

[Description("Returns the details of a descriptor for the input SID.")]  
[WebGet(UriTemplate = "service")]
BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
   public DInfo GetDS(string strS)
   {
            
        bool bRet = false;            
        StringBuilder distFeedfile; 
          
        distFeedfile = new StringBuilder(@"C:\DFeeds\DFeed_20.xml");
        int input = Convert.ToInt32(strS);
        DInfo distInfo; //DInfo is a structure
            
        // Initialize unmanged memory to hold the struct.
        IntPtr dInfoPtr =  Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DInfo)));

        try
        {
                
            bRet = GetDistInfo(distFeedfile, input, dInfoPtr);
            distInfo = (DInfo)(Marshal.PtrToStructure(dInfoPtr, typeof(DInfo)));
            return distInfo;
        }             
        finally
        {
            // Free the unmanaged memory.
            Marshal.FreeHGlobal(dInfoPtr);
        }
}


Everything works fine in my VS Deployment server.
And when I hosted it in my local IIS (with appPool set to net 4.0), first it didn't work, but then after I changed the AppPool settings to enable 32bit (for the native support) and I built the rest service with x86 set, then it worked.
Then I deployed the service on the server, and did similar setting to AppPool. But it gives an 500 error. I know the service is hosted correctly because another simple hello world method works.
Even in the above GetDS method if I comment the call to bRet = GetDistInfo(distFeedfile, input, dInfoPtr);
then the service returns correctly, ofcourse the with structure DInfo with junk data.

What am I missing? Why the native call on the server is not working. Am I missing any settings or installation?

Thanks much in advance.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900