我的 Silverlight 应用程序中有一个 WCF 项目。WCF 项目使用实体框架从数据库中读取,我想将反映行的对象列表传递给 Silverlight 应用程序,这是服务合同;
[ServiceContract]
public interface IGetToolboxItemsService
{
[OperationContract]
List<Control> GetToolboxItems();
[OperationContract]
string ReturnWord(string word);
}
这是完成这项工作的课程
public class GetToolboxItemsService : IGetToolboxItemsService
{
public List<Control> GetToolboxItems()
{
SilverlightScreenDesignerEntities ent = new SilverlightScreenDesignerEntities();
List<Control> controls = new List<Control>();
controls = ent.Controls.ToList();
return controls;
}
public string ReturnWord(string word)
{
return word;
}
}
这就是我在客户端调用服务的方式;
ToolboxServiceReference.GetToolboxItemsServiceClient proxy = new ToolboxServiceReference.GetToolboxItemsServiceClient();
proxy.GetToolboxItemsCompleted += proxy_GetToolboxItemsCompleted;
proxy.GetToolboxItemsAsync();
然后完成的事件就在这里;
void proxy_GetToolboxItemsCompleted(object sender, ToolboxServiceReference.GetToolboxItemsCompletedEventArgs e)
{
var data = e.Result;
}
当我调试服务时,它会运行到数据库并带回一个列表,Controls
该列表是预期的,但是当我尝试通过客户端获取控件列表时收到错误消息。
The remote server returned an error: NotFound
然而,当我尝试简单的返回词时,服务工作正常并且没有任何中断,是否需要额外的步骤,因为我通过了一个对象?
这是web.config;
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
<connectionStrings>
<add name="ModelContainer" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string="data source=MOBINOTE135;initial catalog=BankManager;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="SilverlightScreenDesignerEntities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string="data source=MOBINOTE135;initial catalog=SilverlightScreenDesigner;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>