tôi phát triển (viết lại vào WCF) một tập tin phân tích cú pháp dịch vụ web chấp nhận string[]
và trở ISection[]
nhưng thực sự đây là một tập hợp các giao diện lồng nhau:Dữ liệu Hợp đồng Được biết đến các loại và một tập hợp các giao diện kế thừa nhau
namespace Project.Contracts // Project.Contracts.dll
{
public interface ISection { }
public interface ISummarySection : ISection { }
public interface IDataSection : ISection { }
}
và lớp:
namespace Project.Format.A // Project.Format.A.dll
{
[DataContract]
public class SummarySectionFormatA : ISummarySection { }
[DataContract]
public class DataSectionFormatA : IDataSection { }
}
giao diện dịch vụ và việc thực hiện:
[ServiceContract]
public interface IService // Project.Contracts.dll
{
ISection[] Parse(string format, string[] data);
}
[ServiceKnownType(typeof(SummarySectionFormatA))] // tried this also
[ServiceKnownType(typeof(DataSectionFormatA))]
public class Service : IService // Project.Service.dll
{
public ISection[] Parse(string format, string[] data)
{
return Factory.Create(format).Parse(data);
}
}
tôi đã cố gắng để cấu hình declaredTypes
trên cả hai máy chủ và khách hàng:
<system.runtime.serialization>
<dataContractSerializer>
<declaredTypes>
<add type="Project.Contracts.ISumarySection, Project.Contracts">
<knownType type="Project.Format.A.SummarySectionFormatA, Project.Format.A" />
</add>
<add type="Project.Contracts.IDataSection, Project.Contracts">
<knownType type="Project.Format.A.DataSectionFormatA, Project.Format.A" />
</add>
</declaredTypes>
</dataContractSerializer>
</system.runtime.serialization>
Nhưng vẫn nhận được lỗi tương tự:
"Type 'DataSectionFormatA' with data contract name 'DataSection:http://schemas.example.com/Parse' is not expected.
hoặc
The underlying connection was closed: The connection was closed unexpectedly.
tôi không thể trang trí giao diện với KnownTypeAttribute vì các dự án Hợp đồng không tham chiếu đến các dự án Định dạng và tham chiếu phá vỡ thiết kế. Đó là lý do tại sao tôi muốn sử dụng cấu hình.
Bạn có thể đăng hợp đồng hoạt động dịch vụ của mình không, vui lòng –
@hugh: Chắc chắn, đã cập nhật. – abatishchev