2009-10-24 37 views
1

我的系統是Windows 7旗艦版32位。運行Visual Studio 2010 beta 2定位.Net 4.BadImageFormatException IIS託管的WCF服務Win7 x86,VS2010b2

我有一個項目包含服務合同
一個包含服務的項目。
以及在IIS中承載服務的ASP.NET Web應用程序。 。

我寫使用的ChannelFactory()CreateChannel()...我自己的客戶

每當我跑我的應用程序,它使用ServiceClient和調用方法上的服務,我得到這個錯誤:

An attempt was made to load a program with an incorrect format. 
    (Exception from HRESULT: 0x8007000B) 

我嘗試添加在VS的服務引用,從而使服務客戶端是自動生成的,並不會改變任何東西。

然後我嘗試從VS2010中的Web類別創建一個新的WCF服務應用程序,添加一個服務引用並調用標準的GetData方法,這很好,所以它肯定是我的服務或託管的服務錯誤的...

UPDATE

我注意到,這是錯誤使用wsHttpBindings時,僅出現。 basicHttpBindings工作正常。

我這是怎麼實例化服務:

private IAdminService _AdminService; 

public AdminServiceClient() 
{ 
    _AdminService = new ChannelFactory<IAdminService>(String.Empty) 
         .CreateChannel(); 
} 

客戶端的配置設置:

<system.serviceModel> 
    <client> 
     <endpoint address="http://AdminServices/svcs/AdminService.svc" 
        binding="wsHttpBinding" 
        contract="MyApp.Admin.Model.ServiceContracts.IAdminService" /> 
    </client> 
</system.serviceModel> 

我的服務是這樣的:

public class AdminService : IAdminService 
{ 
    public User GetUserByEmail(string email) 
    { 
     throw new NotImplementedException(); 
    } 

    public void CreateUser(string fullname, string email, 
       string encryptedPassword, 
       string encryptedPasswordQuestion, 
       string encryptedPasswordAnswer) 
    { 
     throw new NotImplementedException(); 
    } 

    public IEnumerable<Application> GetApplications() 
    { 
     IEnumerable<Application> apps = new List<Application>(); 
     // Call data access layer method to retrieve Applications 
     return apps; 
    } 

    public IEnumerable<ApplicationInstance> GetApplicationInstances(
              long? applicationId) 
    { 
     throw new NotImplementedException(); 
    } 

    public Dictionary<string, string> GetApplicationsAndInstances() 
    { 
     Dictionary<string, string> appsAndInstances = 
       new Dictionary<string, string>(); 
     appsAndInstances.Add("Dummy 1", "1"); 
     appsAndInstances.Add("Dummy 2", "2"); 
     return appsAndInstances; 
    } 
} 

我AdminService.svc文件看起來像這個:

<%@ ServiceHost Service="MyApp.Admin.Services.AdminService" %> 

我的服務主機的配置是這樣的:

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
    <compilation debug="true" 
       targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <services> 
     <service name="MyApp.Admin.Services.AdminService"> 
     <endpoint address="" 
        binding="wsHttpBinding" 
        contract="MyApp.Admin.Model.ServiceContracts.IAdminService" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 

我還試圖創建一個新的控制檯應用程序,並添加一個服務引用http://AdminServices/svcs/AdminService.svc - 那也不行。

我添加AdminServices我的hosts文件,我可以瀏覽http://AdminServices/svcs/AdminService.svc,看到了服務信息......

回答

2

最明顯的原因是,你正在裝載一個64位的DLL加載到32位進程或反之亦然。然而,鑑於你正在32位開發盒上運行所有的東西,我認爲情況並非如此。

另一種選擇是使用通用約束這樣的.NET錯誤:

public class SpecificClass: BaseClass: where T : class { } 

如果去掉其中T:類應該只是罰款。

+0

我沒有任何類似的通用約束。 – MartinHN