2

我有一个 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" />

谢谢,

萨钦

4

2 回答 2

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;
}
于 2012-08-08T14:29:23.367 回答
0

我喜欢.NET,它有时太垃圾了。问题是 NameValueCollections。由于某种原因,WCF 在将这些从服务器传递到客户端时遇到了问题。去搞清楚!

于 2012-08-08T15:03:33.793 回答