views:

140

answers:

1

In Silverlight 2, I am attempting to add a new service which will return an object containing two lists from the WCF Service to the Silverlight app on the client. The svc and interface file already contain two contracts which work and are being used. After adding the new service, I click on the "Update Service Reference" option in the Silverlight app and receive the error:

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..."

Even though the web service project rebuilds without error, I think there must be something wrong with the way I have defined the service in the web service project, because when I remove the new service, the remaining two services are updated OK, and if I add a new service which I know is OK, the service reference will update OK. So I don t think it is a problem of endpoints, or the port # etc.

The new service is supposed to return an object which contains two lists.

Any help would be appreciated. Here is the code:

In the interface file:

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 em; [DataMember] public IList 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; } } }

In the service file:

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;

}

} }

Many thanks

Mike Thomas

A: 

James,

Many thanks - I should have though of that. At any rate below was the error. It was just a matter of adding the [DataContractAttribute] attribute to the Employee and School classes, and everything worked fine. This is a frustrating learning process, but it is nice when a solution is revealed.

Mike Thomas

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/%3AICMS ----> 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.