none
Web service is sending out value but client is getting "INET_E_DOWNLOAD_FAILURE" RRS feed

  • Question

  • I created a web service with a single method which is hosted in IIS on windows 10. when i call the web service method with Postman i get a "Could not get any response" message. When i attach the debugger to the web service and call it, i can see that the method is getting hit and sending back the array of values. Postman however never gets the return values.

    interface

        [ServiceContract]
        public interface ISearchService
        {
           
            [OperationContract]
            [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "Searches")]
            SearchRecord[] GetSearches();
    
        }

    Service implementation

            public SearchRecord[] GetSearches()
            {
                return GetAllSearches();
            }
    
            private SearchRecord[] GetAllSearches()
            {
                    IEnumerable<SearchRecord> items = new List<SearchRecord>();
                SearchRecord[] list = null;
                using (SearchProvider ctx = new SearchProvider())
                {
                    try
                    { 
                    items = ctx.Searches;
                    list = items.ToArray();
                    }
                    catch(SqlException ex)
                    {
                        System.Diagnostics.Trace.WriteLine(ex.ToString());
    
                    }
                    catch(Exception ex)
                    {
                        System.Diagnostics.Trace.WriteLine(ex.ToString());
    
                    }
                }
                return list;
            }

    my firewall is turned off. The "SearchRecord" class is decorated with the datacontract attribute. 


    Shawn

    Thursday, November 2, 2017 3:19 PM

All replies

  • Where did you get this example from?

    Thursday, November 2, 2017 6:18 PM
  • You seem to being using EF it looks like, most likely Code first, maybe.

    How do you know that the EF entity being used is a DataContract to WCF as you see it in the example of a DataContract being used? Because without a Datacontract on a class/object as it is shown in the example, then you are not going to see any data on the client-side that called the WCF service.

    Thursday, November 2, 2017 7:43 PM
  • Actually i am using the database first approach. I modified the code generator file to add the Data Contract/Data Member tags during generation.

    SearchRecord model

        using System;
        using System.Collections.Generic;
        
        using System.Runtime.Serialization;
        
        [DataContract]
        public partial class SearchRecord
        {
            [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
            public SearchRecord()
            {
                this.Reminders = new HashSet<Reminder>();
                this.SearchEntries = new HashSet<WorkSearchEntry>();
            }
        
        	[DataMember]
            public System.Guid SearchRecordId { get; set; }
        	[DataMember]
            public System.Guid CaUserId { get; set; }
        	[DataMember]
            public Nullable<System.Guid> RecordType { get; set; }
        	[DataMember]
            public Nullable<System.Guid> ObjectId { get; set; }
        	[DataMember]
            public Nullable<System.Guid> PositionId { get; set; }
        	[DataMember]
            public Nullable<System.Guid> Company { get; set; }
        
        	[DataMember]
            public virtual CaUser CaUser { get; set; }
        	[DataMember]
            public virtual Position Position { get; set; }
            [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        	[DataMember]
            public virtual ICollection<Reminder> Reminders { get; set; }
            [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        	[DataMember]
            public virtual ICollection<SearchEntry> WorkSearchEntries { get; set; }
        }


    Shawn

    Thursday, November 2, 2017 7:54 PM
  • What you should be sending is the DTO, leaving the EF entity behind the WCF service, as datacontracts.

    Maybe you should be considering using a List<T> too.

    All DTO(s) in a project called Entities and all projects have reference to it and know about the DTO(s).

    https://www.codeproject.com/Articles/1050468/Data-Transfer-Object-Design-Pattern-in-Csharp

    https://entitiestodtos.codeplex.com/

    http://automapper.org/

    Thursday, November 2, 2017 8:39 PM
  • Hi Shawn,

    Is there anything missing in SearchRecord class? I did not find the definition for “this.SearchEntries”. I simplify your code, and make a test with below code, it works correctly.

            public SearchRecord[] GetSearches()
            {
                var searches = new SearchRecord[] {
                    new SearchRecord { CaUserId = new Guid(), CaUser =new CaUser { Name= "N1" }  },
                    new SearchRecord { CaUserId = new Guid(), CaUser =new CaUser { Name= "N2" }  },
                    new SearchRecord { CaUserId = new Guid(), CaUser =new CaUser { Name= "N3" }  }
                };
                return searches;
            }
    
    
        [DataContract]
        public partial class SearchRecord
        {
            [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
            public SearchRecord()
            {
                this.Reminders = new HashSet<Reminder>();
                //this.SearchEntries = new HashSet<WorkSearchEntry>();
            }
    
            [DataMember]
            public System.Guid SearchRecordId { get; set; }
            [DataMember]
            public System.Guid CaUserId { get; set; }
            [DataMember]
            public Nullable<System.Guid> RecordType { get; set; }
            [DataMember]
            public Nullable<System.Guid> ObjectId { get; set; }
            [DataMember]
            public Nullable<System.Guid> PositionId { get; set; }
            [DataMember]
            public Nullable<System.Guid> Company { get; set; }
    
            [DataMember]
            public virtual CaUser CaUser { get; set; }
            //[DataMember]
            //public virtual Position Position { get; set; }
            [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
            [DataMember]
            public virtual ICollection<Reminder> Reminders { get; set; }
            //[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
            //[DataMember]
            //public virtual ICollection<SearchEntry> WorkSearchEntries { get; set; }
        }
    
        public class Reminder
        {
            public int Id { get; set; }
            public string Name { get; set; }
        }
    
        public class SearchEntry
        {
        }
    
        public class CaUser
        {
            public string Name { get; set; }
        }
    
    

    To check whether it is related with your class or data, I suggest you make a test with my code.

    If it could not be reproduced with my code, I would suggest you compare the difference, and try to reproduce your issue with modifying my code.

    Best Regards,

    Edward 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 3, 2017 2:34 AM