我有一个WCF服务,在这个服务中我返回一个包含很多属性的类,其中一些是类本身,它有点复杂但不是很大。我在同一个项目上用另一个WCF服务完成了类似的事情,一切正常。但是当我使用它时,这个给了我这个错误。
[System.ServiceModel.CommunicationException] {"An error occurred while receiving the HTTP response to http://xxx/Service.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details."} System.ServiceModel.CommunicationException
内部异常是
[System.Net.WebException] {"The underlying connection was closed: An unexpected error occurred on a receive."} System.Net.WebException
内在的例外是
[System.IO.IOException] {"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."} System.IO.IOException
内在的例外是
[System.Net.Sockets.SocketException] {"An existing connection was forcibly closed by the remote host"} System.Net.Sockets.SocketException
所以,这就是我尝试过的。我想也许我的.svc文件中有一些错误,或者我的.config文件配置中可能有一些错误,但据我所知,没有。然后,我想我应该试着看看我是否可以从服务器向客户端发送一个简单的类型。因此我创建了一个名为GetInt()的方法,它返回7.我在客户端上调用它并且它工作正常。因此,我认为这是我从不受支持的服务器发回的数据。我不明白为什么,因为正如我所说的那样,我之前在同一个项目上发送了复杂类型(就在昨天),这一切都奏效了。无论如何,这是我要发送的课程。也许,有人可以指出可能不支持的内容。或者也许有人知道还有什么可能导致这种情况。
public class Hotels
{
public string Language { get; set; }
public string Datum { get; set; }
public List<HotelListing> HotelListing { get; set; }
}
public class HotelListing
{
public long Id { get; set; }
public string Name { get; set; }
public string Country { get; set; }
public decimal Latitude { get; set; }
public decimal Longitude { get; set; }
public string Category { get; set; }
public List<PhoneNumber> PhoneNumbers { get; set; }
public Address Address { get; set; }
public Content Content { get; set; }
}
public class Content
{
public Description Description { get; set; }
public List<Review> Reviews { get; set; }
public Image Image { get; set; }
public AtrttributeData AtrttributeData { get; set; }
}
public class AtrttributeData
{
public string Link { get; set; }
public string Title { get; set; }
public NameValueCollection Attributes { get; set; }
}
public class Image
{
public string Type { get; set; }
public string ImageURL { get; set; }
public string HotelURL { get; set; }
}
public class Review
{
public string Type { get; set; }
public string Link { get; set; }
public string Author { get; set; }
public string Body { get; set; }
public NameValueCollection Ratings { get; set; }
}
public class Description
{
public string Link { get; set; }
public string Title { get; set; }
public string Body { get; set; }
}
public class Address
{
public string Format { get; set; }
public string Addr1 { get; set; }
public string Addr2 { get; set; }
public string City { get; set; }
public string PostCode { get; set; }
}
public class PhoneNumber
{
public string Type { get; set; }
public string Number { get; set; }
}
有问题的方法是这个
[OperationContract]
Hotels GetHotels();
非常感谢任何帮助。
这是我的配置部分
<binding name="BasicHttpBinding_ITablet" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<snip>
<endpoint address="http://xxx/Service.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITablet"
contract="SupplierInterfaceTabletService.ITablet" name="BasicHttpBinding_ITablet" />
感谢,
萨钦
答案 0 :(得分:1)
尝试返回DataContract(不是Class)。这是一个DataContract,带有另一个DataContract的列表和一个继承的例子。
[DataContract]
public class sDoc
{
[DataMember]
public int sID;
[DataMember]
public int sParID;
[DataMember]
public List<sDocProp> Props;
[DataMember]
public string SessionID;
public string NotDataMember;
}
[DataContract]
[KnownType(typeof(sDocPropStringSV))]
public class sDocProp
{
[DataMember]
public int ID;
[DataMember]
public string Name;
[DataMember]
public ArrivalStatus ArrivalStatus;
}
[DataContract]
public class sDocPropStringSV : sDocProp
{
[DataMember]
public string Value;
}
答案 1 :(得分:0)
我喜欢.NET,有时候它太垃圾了。问题是NameValueCollections。由于某种原因,WCF将这些从服务器传递到客户端时出现问题。去图!