【问题标题】:Silverlight 2, Cannot Update Service Ref with New ServiceSilverlight 2,无法使用新服务更新服务引用
【发布时间】: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


【解决方案1】:

詹姆斯,

非常感谢 - 我应该考虑到这一点。无论如何,以下是错误。只需将[DataContractAttribute] 属性添加到EmployeeSchool 类,一切正常。这是一个令人沮丧的学习过程,但如果能找到解决方案,那就太好了。

An ExceptionDetail, likely created by `IncludeExceptionDetailInFaults=true`, whose value is:
System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.DataContractSerializerOperationBehavior
 contract: http://tempuri.org/:ICMS ----> System.Runtime.Serialization.InvalidDataContractException: Type 'CMSSilverlight.Web.Employee' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.  See the Microsoft .NET Framework documentation for other supported types.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-22
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    • 2010-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多