0
votes

Using VS2012 and NetTcpBinding. I am getting the following error when I call the serviceContract from the client - The service is hosted in IIS:

There was an error while trying to serialize parameter CS.ServiceContracts.Zzzzzz.Common:GetZipCodesResult. The InnerException message was 'Type 'System.DelegateSerializationHolder+DelegateEntry' with data contract name 'DelegateSerializationHolder.DelegateEntry:http://schemas.datacontract.org/2004/07/System' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.

Here is my ServiceContract:

  [ServiceContract(SessionMode = SessionMode.Allowed, Namespace = "CS.ServiceContracts.Zzzzzz.Common",
    Name = "IZzzzzzCommonService")]
public interface IZzzzzzCommonService
{
    [OperationContract]
    GetZipCodesResponse GetZipCodes(GetZipCodesRequest request);
}

Here is my DataContract:

[DataContract]
[Serializable]
public class GetZipCodesResponse : ResponseBase
{
    [DataMember(IsRequired = true)]
    public List<ZipCodes> ZipCodes { get; set; }
}

And here is the ResponseBase:

[DataContract]
[Serializable]
[KnownType(typeof(GetZipCodesResponse)), XmlInclude(typeof(GetZipCodesResponse))]
public class ResponseBase
{
    [DataMember(IsRequired = true)]
    public int ResponseCode { get; set; }

    [DataMember(IsRequired = false)]
    public int ReasonCode { get; set; }

    [DataMember(IsRequired = false)]
    public string ReasonText { get; set; }
}

Here is the Implementation of the serviceContract Interface:

public class ZzzzzzCommonService : IZzzzzzCommonService
{
 public GetZipCodesResponse GetZipCodes(GetZipCodesRequest request)
    {
        var response = new GetZipCodesResponse();
        try
        {
            response.ZipCodes = ZipCodes.GetCustom(request.ZipCode, request.City, request.State);

        }
        catch (Exception ex)
        {
            this.BuildExceptionResponse(response, ex);
        }

        return response; // I get to this line ok, but here is where the error occurs
    }
}

And here is the client code where I am calling the Service:

 public void ZipCodes()
    {
        var endPoint = new EndpointAddress(
            "net.tcp://localhost/CS.WebService.Zzzzzz.Common/ZzzzzzCommonService.svc");

        var binding = new NetTcpBinding { TransferMode = TransferMode.Buffered, SendTimeout = TimeSpan.MaxValue, ReceiveTimeout = TimeSpan.MaxValue, MaxReceivedMessageSize = 100000000, MaxBufferSize = 100000000 };

        using (var channel = new ChannelFactory<IZzzzzzCommonService>(binding, endPoint))
        {
            try
            {
                channel.Endpoint.Contract.SessionMode = SessionMode.Allowed; 
                var proxy = channel.CreateChannel();
                var request = new GetZipCodesRequest();

                request = new GetZipCodesRequest { ZipCode = "32701" };
                response = proxy.GetZipCodes(request);
            }
        }

   }

I have debugged the code and I am getting into the entity and the dataSet is populated with the appropriate rows but when it sends the dataset back is when I get the errors.

Not sure what I am missing. I believe I have the serviceContract and dataContract members decorated correctly so not sure why it is having problems serializing the List.

1
Could you please provide code for ZipCodes classVlad Bezden

1 Answers

0
votes

The problem was the ZipCode class. It was an Entity class and it was not able to be serialized. So I deconstructed the class and it was able to send it back to the client.