11

I've got a simple WCF service that has worked fine while I've been testing on my dev machine.

Now I've moved the web service to a web server, and I'm running the service (in debug mode) at http://mydomain.com:8005. Opening a web browser to that URL shows the expected service page, and if I put a breakpoint on the server inside the interface I'm calling, it hits the breakpoint and returns the expected data... but on the client side it comes back with the following error:

An error occurred while receiving the HTTP response to http://mydomain.com:8005/. 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.

More clues: the interface signature is:

IEnumerable<MyClass> GetThings(out string errMsg);

where MyClass is defined as Serializable, and the definitions are identical between client and server.

Any ideas what secret switches I need to flip?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Shaul Behr
  • 36,951
  • 69
  • 249
  • 387
  • How are you hosting your WCF service? In IIS?? Does IIS run on port 8005 on that machine?? Also: please **show us** your service-side config - we can't read your mind (or harddisk) from here..... – marc_s Mar 15 '11 at 10:39
  • 1
    WCF also needs to have **concrete classes** to pass data around (since it all needs to be XML-serializable and must be capable of being expressed in XML schema - interfaces aren't well suited). I believe it won't be able to pass back an `IEnumerable` - try using a `List` or a concrete type instead. Any luck? – marc_s Mar 15 '11 at 10:50
  • 1
    @marc_s - self-hosted, marked as `[Serializable]` and `[DataContract]`; all public members marked as `[DataMember]`. – Shaul Behr Mar 15 '11 at 10:57
  • 1
    @marc_s - The concrete class comment is the answer. Please propose it as an answer for me to mark it correct. Thanks! – Shaul Behr Mar 15 '11 at 11:03
  • Done - thanks! Glad I was able to help – marc_s Mar 15 '11 at 11:22
  • I solved my issue as I explained here: http://stackoverflow.com/questions/5537794/error-while-deserializing-the-object-in-wcf/8415908#8415908 – Adi Dec 07 '11 at 13:26

8 Answers8

23

WCF also needs to have concrete classes to pass data around (since it all needs to be XML-serializable and must be capable of being expressed in XML schema - interfaces aren't well suited).

I believe it won't be able to pass back an IEnumerable<T> - try using a List<T> (or an T[] array) or a concrete type instead.

Any luck?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
8

I had the same problem because I was returning an insanely large amount of record from the server, i added the following line to my wcf config file and it worked.

<system.web>
    <httpRuntime maxRequestLength ="262144" executionTimeout="103600"/>
</system.web>
zxnet
  • 161
  • 2
  • 2
  • I had a big file also, I already changed the maxRequestLength but the executionTimeout did the trick. – StefanHa Jul 25 '13 at 16:32
4

Don't define MyClass as Serializable. Mark it as [DataContract] and it's properties as [DataMember].

If you can't, well... I think I've seen that question lying around here as well.

EDIT

While there is nothing inherently blocking [Serializable] will cause your serialization to perhaps process more than it can handle.

EDIT 2

marc_s's comment got it right

Vincent Vancalbergh
  • 3,267
  • 2
  • 22
  • 25
  • 1
    It's marked as `[Serializable]` and `[DataContract]`; all public members marked as `[DataMember]`. Does `[Serializable]` do any damage, or is it just unnecessary? – Shaul Behr Mar 15 '11 at 10:59
2

Late answer to the party, but I got the same error.

Turns out, you cannot use abstract classes for data contract members. I had to use the following:

[DataContract]
public class MyClass {
    [DataMember]
    public A MyProperty { get; set; }
}

[DataContract]
[KnownType(typeof(B))]
[KnownType(typeof(C))]
public class A {

}

[DataContract]
public class B : A {

}

[DataContract]
public class C : A {

}

In order to allow WCF to serialize something like

var myClass = new MyClass();
myClass.MyProperty = new B();
Ezra Bailey
  • 1,434
  • 13
  • 25
0

Update your Entity if any changes made in your previous tables and didn't update your entity also this error will occur

0

I just leave this here just in case someone need it. I came across with the same error. I was calling my service which has an argument of the type Dictionary<int, string> and one of the key/value pairs had the string value set to null.

I changed the code to make sure there were no null values and it worked

Alberto Sadoc
  • 107
  • 2
  • 5
0

Just faced the exact same problem but it was caused by security protocol type hardcoded to TLS 1.2 while the service was deployed to 2008 server without R2 (and 32 bit to boot, which means non-upgradable to R2).

This is a very unlikely scenario for anyone else, but thought I'd mention.

If anyone is in the same situation and has a line of code like this, you know why you are getting the error now:

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
ajeh
  • 2,652
  • 2
  • 34
  • 65
0

I have faced the same issue. It was the issue of port address of EndpointAddress. In Visual studio port address of your file (e.g. Service1.svc) and port address of your wcf project must be the same which you gives into EndpointAddress. Let me describe you this solution in detail.

There are two steps to check the port addresses.

  1. In your WCF Project right click to your Service file (e.g. Service1.svc) -> than select View in browser now in your browser you have url like http://localhost:61122/Service1.svc so now note down your port address as a 61122

  2. Righ click your wcf project -> than select Properties -> go to the Web Tab -> Now in Servers section -> select Use Visual Studio Development Server -> select Specific Port and give the port address which we have earlier find from our Service1.svc service. That is (61122).

Earlier I have different port address. After Specifying port address properly which I have given into EndpointAddress, my problem was solved.

I hope this might be solved your issue.

Dilip Langhanoja
  • 4,455
  • 4
  • 28
  • 37