【发布时间】:2017-01-01 19:20:55
【问题描述】:
我有一个带有 EF(实体框架)的 WCF Web 服务,用于访问数据库中的产品表。我在我的项目中添加了一个测试客户端,用于在输入 ID 时显示退货产品。
这是我在服务接口中的方法:
[OperationContract]
VareWS VareWSGet(String barcode);
这是服务中实现的方法:
public VareWS VareWSGet(string barcode)
{
ExamDBEntities3 context = new ExamDBEntities3();
var vareEntity = (from v
in context.Vare
where v.barcode == barcode
select v).FirstOrDefault();
if (vareEntity != null)
return TranslateProductEntityToProduct(vareEntity);
else
throw new Exception("Invalid product id");
}
这是用于翻译产品实体的私有方法:
private VareWS TranslateProductEntityToProduct(
Vare vareEntity)
{
VareWS vare = new VareWS();
vare.navn = vareEntity.navn;
vare.pris = (int)vareEntity.pris;
return vare;
}
在我的客户端中,我使用此代码在我的 Web 服务中调用该方法:
sc = new Service1Client();
string inputID = TextBox1.Text;
VareWS v = sc.VareWSGet(inputID);
服务引用已成功添加,但我收到一条错误消息,提示“无法将类型 'ServiceReference1.VareWS' 隐式转换为 'VareWS'” 我不确定如何更正此错误,因为我已指定与我的服务客户端的连接。如果您需要更多信息,请告诉我,谢谢。
使用语句:
客户:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExamOpg.ServiceReference2;
服务:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
【问题讨论】:
-
我能在那个文件中看到所有的 using 语句吗?
-
这里是客户端的使用语句:
-
使用系统;使用 System.Collections.Generic;使用 System.Linq;使用 System.Web;使用 System.Web.UI;使用 System.Web.UI.WebControls;使用 ExamOpg.ServiceReference2;
-
对不起,我的格式化好像失败了,我会在原帖中添加。
-
你在
ExamOpg.ServiceReference2中也有VareWS吗?
标签: c# entity-framework web-services wcf