参数必须是DomainService公开的实体类型?
尝试在 SL 应用程序中实现域服务并收到以下错误:
域方法“CreateSharePointFolder”的参数“spFolderCreate”必须是由 DomainService 公开的实体类型。
[EnableClientAccess()]
public class FileUploadService : DomainService
{
public void CreateSharePointFolder(SharePointFolderCreate spFolderCreate)
{
SharePointFolder spf = new SharePointFolder();
spf.CreateFolder_ClientOM(spFolderCreate.listName, spFolderCreate.fileName);
}
[OperationContract]
void CreateSharePointFolder(SharePointFolderCreate spFolderCreate);
[DataContract]
public class SharePointFolderCreate
{
private string m_listName;
private string m_fileName;
[DataMember]
public string listName
{
get { return m_listName; }
set { m_listName = value; }
}
[DataMember]
public string fileName
{
get { return m_fileName; }
set { m_fileName = value; }
}
}
那么我是否缺少一些简单的东西来使这一切正常工作?
Trying to implement a domain service in a SL app and getting the following error:
Parameter 'spFolderCreate' of domain method 'CreateSharePointFolder' must be an entity type exposed by the DomainService.
[EnableClientAccess()]
public class FileUploadService : DomainService
{
public void CreateSharePointFolder(SharePointFolderCreate spFolderCreate)
{
SharePointFolder spf = new SharePointFolder();
spf.CreateFolder_ClientOM(spFolderCreate.listName, spFolderCreate.fileName);
}
[OperationContract]
void CreateSharePointFolder(SharePointFolderCreate spFolderCreate);
[DataContract]
public class SharePointFolderCreate
{
private string m_listName;
private string m_fileName;
[DataMember]
public string listName
{
get { return m_listName; }
set { m_listName = value; }
}
[DataMember]
public string fileName
{
get { return m_fileName; }
set { m_fileName = value; }
}
}
So am I missing something simple here to make this all work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
框架可能正在推断预期的操作,因为函数名称 (CreateSharePointFolder) 前面有“Create”一词。此行为的详细信息可以在此处找到,
尽管这对于 DomainServices 来说没什么问题和EntityFramework,根据该文章中的信息,可以推断以“Delete”开头的方法将执行实体的删除,因此必须接受实体作为参数。对于“Create”或“Insert”前缀方法也是如此。只有“Get”或“Select”方法可以采用非实体参数,从而可以将数字 id(例如)传递给“Get”方法。
尝试暂时将方法名称更改为“BlahSharePointFolder”,看看是否是这种推理约定导致了您的问题。
此外,由于没有为 SharePointFolderCreate DC 定义元数据,因此您可能需要使用 [MetadataType] 属性来装饰该类(除了 [DataContract] 属性之外)。如果您使用 DomainServiceClass 向导并指向 EF 模型,您将了解如何实现这一点。底部有一个用于生成元数据的复选框。在您的解决方案.Web 项目中的某个位置,您应该可以找到domainservice.metadata.cs 文件。在此文件中,您将找到如何使用 [MetadataType] 属性的示例。
为了让 RIA WCF 服务能够正确地使用您自己的方法,您需要确保参数列表中存在的所有实体至少有一个在其元数据类中定义了 [Key] 属性的成员,并且该实体返回到您的 DomainService 在“Get”方法中。
HTH
李
It may be that the framework is inferring the intended operation because you have the word "Create" prefixing the function name (CreateSharePointFolder). Details of this behaviour can be found here
Although that is all fine for DomainServices and EntityFramework, following the information in that article, it can be inferred that methods beginning "Delete" will be performing a delete of an entity, so must accept an entity as a parameter. The same is true for "Create" or "Insert" prefixed methods. Only "Get" or "Select" methods can take non-entity parameters, making it possible to pass a numeric id (for example) to a "Get" method.
Try changing your method name temporarily to "BlahSharePointFolder" to see if it is this convention of inferrance that's causing your problem.
Also, as there is no metadata defined for your SharePointFolderCreate DC, you might need to decorate the class (in addition to the [DataContract] attribute) with the [MetadataType] attribute. You will see how to implement this if you used the DomainServiceClass wizard and point to an EF model. There is a checkbox at the bottom for generating metadata. Somewhere in your solution.Web project you should find a domainservice.metadata.cs file. In this file, you will find examples of how to use the [MetadataType] attribute.
For the RIA WCF service to work correctly with your own methods, you need to ensure that all entities existing on the parameter list have at least one member with a [Key] attribute defined in their metadata class, and that the entity is returned somewhere on your DomainService in a "Get" method.
HTH
Lee