【发布时间】:2009-08-30 13:22:36
【问题描述】:
在 Silverlight 2 中,我正在尝试添加一个新服务,该服务会将包含两个列表的对象从 WCF 服务返回到客户端上的 Silverlight 应用程序。 svc 和 interface 文件已经包含两个可以工作并正在使用的合约。添加新服务后,我点击 Silverlight 应用程序中的“更新服务参考”选项并收到错误:
There was an error downloading "http://localhost:3005/CMS.svc" ...
Metadata contains a reference that cannot be resolved "http://localhost:3005/CMS.svc" ...The client and service bindings may be mismatched...
虽然web服务项目rebuild没有报错,但我认为我在web服务项目中定义服务的方式肯定有问题,因为当我删除新服务时,剩下的两个服务都更新好了,如果我添加一个我知道没问题的新服务,服务参考将更新好。所以我不认为是端点的问题,或者端口号等问题。
新服务应该返回一个包含两个列表的对象。
代码如下:
在接口文件中:
namespace CMSSilverlight.Web
{
// NOTE: If you change the interface name "ICMS" here, you must also update the reference to "ICMS" in Web.config.
[ServiceContract]
public interface ICMS
{
[OperationContract]
POCollection GetPOCollection(String s);
}
[DataContract]
public class POCollection
{
[DataMember]
public IList<Employee> em;
[DataMember]
public IList<School> sc;
}
public class Employee
{
public string EmpID { get; set; }
public string EmpName { get; set; }
public Employee(string empID, string empName)
{
this.EmpID = empID;
this.EmpName = empName;
}
}
public class School
{
public string SchID { get; set; }
public string SchName { get; set; }
public School(string schID, string schName)
{
this.SchID = schID;
this.SchName = schName;
}
}
}
在服务文件中:
namespace CMSSilverlight.Web
{
{
public POCollection GetPOCollection(String sParam)
{
IList<Employee> empList = new List<Employee>();
for (int i = 0; i < 5; i++)
{
empList.Add(new Employee(i.ToString(), i.ToString() + " Emp Name"));
}
IList<School> schList = new List<School>();
for (int i = 0; i < 5; i++)
{
schList.Add(new School(i.ToString(), i.ToString() + " Sch Name"));
}
POCollection po = new POCollection()
{
em = empList,
sc = schList
};
return po;
}
}
}
【问题讨论】:
-
你能在两个配置文件中包含
部分吗? -
在浏览器中右键单击/查看新服务会发生什么?
标签: wcf silverlight silverlight-2.0