【发布时间】:2009-10-24 19:50:52
【问题描述】:
我的系统是 Windows 7 Ultimate 32 位。运行面向 .Net 4 的 Visual Studio 2010 beta 2。
我有一个包含服务合同的项目。
包含服务的项目。
以及一个在 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 方法,它工作正常,所以肯定是我的服务或服务的托管出错了...
更新
我注意到这个错误只在使用 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 并查看服务信息...
【问题讨论】:
标签: wcf iis visual-studio-2010