简体   繁体   中英

WCF Web Service error: “Service endpoint binding not using HTTP protocol”?

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?

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?

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>

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

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();

如果在以前的表中进行了任何更改并且未更新您的实体,则更新您的实体也会发生此错误

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

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;

I have faced the same issue. It was the issue of port address of EndpointAddress . In Visual studio port address of your file (eg 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 (eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM