我已經託管Rest WCF
我的IIS 7
。我測試了一切,除了導入dll
之外,它工作正常。我的實例類代碼如下:無法加載第三方DLL在IIS託管休息WCF服務
[OperationContract, WebInvoke(Method = "GET", UriTemplate = "/getname?name={name}&age={age}", ResponseFormat = WebMessageFormat.Json)]
bool getname(string name, string age);
[OperationContract, WebInvoke(Method = "GET", UriTemplate = "/getcallfromdll?name={name}&age={age}", ResponseFormat = WebMessageFormat.Json)]
bool getcallfromdll(string name, string age);
鑑於上述方法的定義是:
public string getname(string name, int len)
{
return "It's working";
}
public string getcallfromdll(string name, int len)
{
return UnsafeNativeMethods.getvalue(name, len); //Unsafe.. is a internal structure
}
internal static class UnsafeNativeMethods
{
const string _dllLocation = "school.dll";
[DllImport(_dllLocation, CallingConvention = CallingConvention.Cdecl)]
public static extern bool getvalue(string name, String len);
}
當試圖運行localhost:8085/service.svc/getname?name=kajn&len=21
:它返回"It's working"
,這是正確的,但每當我試圖打電話localhost:8085/service.svc/getcallfromdll?name=kajn&len=21
:它返回The server encountered an error processing the request. See server logs for more details.
我搜索了它,並以某種方式我知道這一切發生,由於服務沒有打包找到DLL
。爲了解決這個問題,我試圖把我的DLL在以下的地方,但它並沒有幫助我:(:
- SYSTEM32/INETSRV
- Syswow64資料/ INETSRV
- 在bin文件夾
- 我也把。在項目中存在相同的文件夾
但沒有什麼對我的作品請建議我一個解決方案
注:有沒有問題與dll,因爲我從自己託管的WCF應用程序調用dll方法,它的工作完美。那時我把我的dll放入bin/debug
文件夾。
不,我不能添加'school.dll'作爲參考,因爲它是我自己創建的'native dll'。不,它不依賴於另一個DLL。我無法理解你。如果你不介意的話請多解釋一下 –
是的,對不起,我不是很精確。我通常將非託管dll添加到項目文件中,作爲普通項目,並且在「複製到輸出目錄」值的「複製始終」下指定。幾個其他建議 - 如果你有32位DLL,在IIS下的應用程序池嘗試設置「啓用32ibt應用程序」爲true。您也可以嘗試在調試器中運行您的應用程序,以便您可以看到您收到的錯誤消息。 –
P.S.我實際上解僱了一個VS,並創建了與你非常相似的場景,所以我肯定有可能:) –