2012-08-17 99 views
0

我已經在C#中編寫了一個web服務,並試圖在IIS 7.0上託管它。考慮下面的代碼,這個代碼工作正常,可以在IIS 7.0上託管,沒有任何問題:在IIS 7.0(不是WCF)中託管webservice

using System; 
using System.Collections.Generic; 
using System.Collections.Specialized; 
using System.Linq; 
using System.Web; 
using System.Web.Services; 
using VMware; 

namespace vmareService 
{ 
/// <summary> 
/// Summary description for Service1 
/// </summary> 
[WebService(Namespace = "http://tempuri.org/")] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
[System.ComponentModel.ToolboxItem(false)] 
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the  following line. 
// [System.Web.Script.Services.ScriptService] 
public class Service1 : System.Web.Services.WebService 
{ 

    [WebMethod] 

    public void logintoVmware(string URL, string username, string password) 
      { 
     VMware.Vim.VimClient client = new VMware.Vim.VimClient(); 

    } 

} 
} 

現在,如果我想這個方法返回我的會話ID,我改變我的代碼如下:

using System; 
using System.Collections.Generic; 
using System.Collections.Specialized; 
using System.Linq; 
using System.Web; 
using System.Web.Services; 
using VMware; 

namespace vmareService 
{ 
/// <summary> 
/// Summary description for Service1 
/// </summary> 
[WebService(Namespace = "http://tempuri.org/")] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
[System.ComponentModel.ToolboxItem(false)] 
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the  following line. 
// [System.Web.Script.Services.ScriptService] 
public class Service1 : System.Web.Services.WebService 
{ 

    [WebMethod] 

    //public void logintoVmware(string URL, string username, string password) 
    public VMware.Vim.UserSession logintoVmware(string URL, string username, string password) 
    { 
     VMware.Vim.VimClient client = new VMware.Vim.VimClient(); 
     VMware.Vim.UserSession session; 
     session = client.Login(URL, username, password); 
     return session; 

    } 

} 
} 

現在雖然我已經在我的代碼中引用的vmware.vim.dll,也已包括託管在IIS 7.0我的文件夾中的文件,,我收到以下錯誤信息:

Server Error in '/vmService' Application. 

Could not load file or assembly 'VMware.Vim, Version=5.0.0.0, Culture=neutral,  PublicKeyToken=10980b081e887e9f' or one of its dependencies. The system cannot find the file specified. 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'VMware.Vim, Version=5.0.0.0, Culture=neutral, PublicKeyToken=10980b081e887e9f' or one of its dependencies. The system cannot find the file specified. 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Assembly Load Trace: The following information can be helpful to determine why the assembly 'VMware.Vim, Version=5.0.0.0, Culture=neutral, PublicKeyToken=10980b081e887e9f' could not be loaded. 


WRN: Assembly binding logging is turned OFF. 
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. 
Note: There is some performance penalty associated with assembly bind failure logging. 
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. 

Stack Trace: 


[FileNotFoundException: Could not load file or assembly 'VMware.Vim, Version=5.0.0.0,  Culture=neutral, PublicKeyToken=10980b081e887e9f' or one of its dependencies. The system cannot find the file specified.] 
System.Signature._GetSignature(SignatureStruct& signature, Void* pCorSig, Int32 cCorSig, IntPtr fieldHandle, IntPtr methodHandle, IntPtr declaringTypeHandle) +0 
System.Signature..ctor(RuntimeMethodHandle methodHandle, RuntimeTypeHandle declaringTypeHandle) +236 
System.Reflection.RuntimeMethodInfo.get_Signature() +91 
System.Reflection.RuntimeMethodInfo.get_ReturnType() +19 
System.Reflection.RuntimeMethodInfo.ToString() +36 
System.Web.Services.WebMethodReflector.GetMethods(Type type) +255 
System.Web.Services.Description.ServiceDescriptionReflector.Reflect(Type type, String url) +77 
System.Web.Services.Protocols.DocumentationServerType..ctor(Type type, String uri) +203 
System.Web.Services.Protocols.DocumentationServerProtocol.Initialize() +388 
System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response) +75 
System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) +143 

[InvalidOperationException: Unable to handle request.] 
System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) +458971 
System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +285 

[InvalidOperationException: Failed to handle request.] 
System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +401754 
System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +281 
System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +89 
System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +425 
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +263 

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

任何幫助將是APPR eciated ..

感謝

+0

你應該確保這個文件在你的/ bin文件夾中。如果是,那麼你應該調查它的潛在依賴關係。請記住,僅僅因爲這個文件在那裏並不意味着所有依賴的dll都可用。 – 2012-08-17 13:47:50

+0

嗨,喬爾,天知道這個論壇救了我多少次。你是一個天才,我真的很想爲你感謝你。 – 2012-08-17 15:12:30

+0

這是否解決了您的問題?如果確實如此,我會將其作爲可行的答案發布。 – 2012-08-17 15:20:48

回答

0

從評論粘貼:

你應該確保這個文件是在你的/ bin文件夾。如果是,那麼你應該調查它的潛在依賴關係。請記住,僅僅因爲這個文件在那裏並不意味着所有依賴的dll都可用。

+0

全部完成全部好,問題出現在c:\ windir \ assembly中缺失的程序集 – 2012-08-17 21:15:35

+0

這樣的註釋會對其他讀者更有幫助,前提是您說明缺少哪個程序集。 – Chris 2014-01-29 17:36:55