在客户端应用程序中使用wcf数据服务 [英] Consume wcf Data service in Client Application

查看:76
本文介绍了在客户端应用程序中使用wcf数据服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Entity框架创建WCF数据服务,我有以下问题。

I am creating WCF Data Service with Entity framework, i have following questions.

1.我已安装VS2010用实体框架来验证WCF数据服务,这样可以吗?

1.I have installed VS2010 to acehieve WCF Data Service with Entity framework, is this fine?

2.i按照以下步骤实现

2.i followed following steps to achieve

- 创建edmx文件并选中我想要使​​用的表,视图和SP

- Created edmx file and selected tables,views and SPs that i want to use

- 使用函数import导入复杂类型的SP。

- imported SP with complex type by using function import.

- 创建WcfDataservice(.svc文件)。

- Created WcfDataservice (.svc File).

- 在SVC文件中,我添加了[webget]方法,如下所示。

- in SVC File i have added [webget] method as follows.

         [WebGet]

        public List< GetSearchResultWithComplextype_Result> GetSearchResultComplextype(string email,string Title,string Color)

        {

           实体db = new Entities();

            var query = db.GetSearchResultWithComplextype(email,Title,Color);

           列表与LT; GetSearchResultWithComplextype_Result> caseList = query.ToList< GetSearchResultWithComplextype_Result>();

            return caseList;

        }

        [WebGet]
        public List<GetSearchResultWithComplextype_Result> GetSearchResultComplextype(string email, string Title, string Color)
        {
            Entities db = new Entities();
            var query = db.GetSearchResultWithComplextype(email, Title, Color);
            List<GetSearchResultWithComplextype_Result> caseList = query.ToList<GetSearchResultWithComplextype_Result>();
            return caseList;
        }

- 创建了一个客户端应用程序并添加了服务引用。

- created one more client application and added service reference.

- 在客户端应用程序中调用此方法如下。

- in client application calling this method as follows.

private void GetSearchResult()

        {

           string serviceURL =" http:// localhost:1319 / MMRWCFDataService.svc / " ;;

            string paramemail = txtemail.Text;

            string paramtitle = txttitle.Text;

            string paramcolor = txtcolor.Text;

            string strparam =" emailid ='" + paramemail +"'& LocalTitle ="" + paramtitle +"'& ColorGrouping ="" + paramcolor +"'" ;;

            string url = serviceURL +" GetSearchResultComplextype?" + strparam;

            DataServiceContext context1 = new DataServiceContext(new Uri(serviceURL));

private void GetSearchResult()
        {
           string serviceURL ="http://localhost:1319/MMRWCFDataService.svc/";
            string paramemail = txtemail.Text;
            string paramtitle = txttitle.Text;
            string paramcolor = txtcolor.Text;
            string strparam = "emailid='" + paramemail + "'& LocalTitle='" + paramtitle + "'& ColorGrouping='" + paramcolor + "'";
            string url = serviceURL + "GetSearchResultComplextype?" + strparam;
            DataServiceContext context1 = new DataServiceContext(new Uri(serviceURL));

            IEnumerable的< GetSearchResultWithComplextype_Result> empResult1 =  context1.Execute< GetSearchResultWithComplextype_Result>(new Uri(url));

            grdSearch.DataSource = empResult1;

            grdSearch.DataBind();

}

            IEnumerable<GetSearchResultWithComplextype_Result> empResult1 = context1.Execute<GetSearchResultWithComplextype_Result>(new Uri(url));
            grdSearch.DataSource = empResult1;
            grdSearch.DataBind();
}

  - 我收到的错误为"关闭类型MMRClient.MMRServiceReference.GetSearchResultWithComplextype_Result没有相应的元素可设置的财产。"与网格绑定

 - I am getting error as "The closed type MMRClient.MMRServiceReference.GetSearchResultWithComplextype_Result does not have a corresponding element settable property." while bind with the grid

如何解决此错误,或者如何使用复杂类型SP在客户端应用程序中使用wcfData服务会更好。

how to solve this error, or it will be better how to consume, wcfData service in client application using Complex type SP.

问候,

M.Seenuvasan

Regards,
M.Seenuvasan

 

推荐答案

对于#1,它绝对是推荐的方式。

As for #1, it is definitely the reccommended way.

至于#2 - 目前客户端库不支持解析返回复杂类型的服务操作的结果。这是一个已知的限制,但如果您想表达您对此功能的兴趣,请在我们的网站上投票:
http:/ /dataservices.mswish.net/

As for #2 - Currently the client library doesn't support parsing results of service operations returning complex types. This is a known limitation, but if you want to express your interest in this feature please vote for it on our site here: http://dataservices.mswish.net/

有可能的解决方法,但每种方法都涉及使用某种XML解析技术手动解析服务操作的响应(XmlReader,XLinq) ,...)。

There are possible workaround, but each will involve parsing the response of the service operation manually using some kind of XML parsing technique (XmlReader, XLinq, ...).

谢谢,


这篇关于在客户端应用程序中使用wcf数据服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆