locked
Failing to get response from the web service RRS feed

  • Question

  • I have a fairly simple service running on the other machine. When I try to call function on that service I have it fails when sending back the request. I have used Microsoft Service Trace Viewer and got the inner exception of the moment that service is failing:

    Type 'System.Net.WebException' with data contract name 'WebException:http://schemas.datacontract.org/2004/07/System.Net' 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.</

    Code for interface:

    Imports System.Net
    
    <ServiceKnownType(GetType(Result))>
    <ServiceContract> _
    Public Interface ISocialMedia
    
        <OperationContract()>
        Function PostToTwitter(ByVal Token As String, ByVal TokenSecret As String, ByVal software As SoftwareType, ByVal status As String) As Result
    
    End Interface
    
    <Serializable>
    <DataContract()>
    Public Class Result
        <DataMember()>
        Public Property Response As WebResponse
        <DataMember()>
        Public Property Exception As Exception
    End Class
    
    <Serializable>
    Public Enum SoftwareType
        <EnumMember()>
            A
        <EnumMember()>
            G
        <EnumMember()>
            S
    End Enum
    I am quite new to web services and how it works so a bit confused why this is happening. The exception says that I should use KnownTypeAttribute which I have added, but still no luck. 

    Monday, October 12, 2015 1:13 PM

Answers

  • Public Class Result
       
    <DataMember()>
       
    Public Property Response As WebResponse
       
    <DataMember()>
       
    Public Property Exception As Exception
    End Class

    WebResponse is what your error message is talking about, and it's not talking about Result.

    https://msdn.microsoft.com/en-us/library/system.servicemodel.serviceknowntypeattribute(v=vs.110).aspx

    And you are at the point that you need to find simple examples of how to work with WCF Web services, which there are plenty of them you can find by using Bing or Google. Myself, I went out and got a book on WCF when I wanted to learn how to use WCF about 9 years ago. Maybe, you should consider getting a book.

    • Proposed as answer by Grady_Dong Monday, October 19, 2015 7:25 AM
    • Marked as answer by Grady_Dong Monday, October 19, 2015 7:29 AM
    Monday, October 12, 2015 3:25 PM