WCF Web服务错误:“服务端点绑定不使用HTTP协议”?

时间:2022-01-25 20:31:35

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

我有一个简单的WCF服务,在我的开发机器上进行测试时工作正常。

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:

现在我已将Web服务移动到Web服务器,并且我正在http://mydomain.com:8005上运行该服务(在调试模式下)。打开Web浏览器到该URL显示预期的服务页面,如果我在我正在调用的接口内的服务器上放置一个断点,它会命中断点并返回预期的数据......但是在客户端它返回出现以下错误:

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.

接收到http://mydomain.com:8005/的HTTP响应时发生错误。这可能是由于服务端点绑定不使用HTTP协议。这也可能是由于服务器中止HTTP请求上下文(可能是由于服务关闭)。请参阅服务器日志以获取更多详

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.

其中MyClass定义为Serializable,客户端和服务器之间的定义相同。

Any ideas what secret switches I need to flip?

有什么想法我需要翻转什么秘密开关?

8 个解决方案

#1


22  

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).

WCF还需要具有传递数据的具体类(因为它都需要是XML可序列化的,并且必须能够以XML模式表示 - 接口不太适合)。

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.

我相信它无法传回IEnumerable - 尝试使用List (或T []数组)或具体类型。

Any luck?

#2


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.

我遇到了同样的问题,因为我从服务器返回了大量的记录,我将以下行添加到我的wcf配置文件中并且它有效。

<system.web>
    <httpRuntime maxRequestLength ="262144" executionTimeout="103600"/>
</system.web>

#3


4  

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

不要将MyClass定义为Serializable。将其标记为[DataContract],将其属性标记为[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.

虽然没有任何固有的阻塞[Serializable]会导致序列化处理的可能性超过其处理能力。

EDIT 2

marc_s's comment got it right

marc_s的评论说得对

#4


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

为了让WCF能够序列化类似的东西

var myClass = new MyClass();
myClass.MyProperty = new B();

#5


0  

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

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

#6


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.

我只是留在这里,万一有人需要它。我遇到了同样的错误。我正在调用我的服务,其服务类型为Dictionary ,其中一个键/值对的字符串值设置为null。 ,string>

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

我更改了代码以确保没有空值并且它有效

#7


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).

刚刚面临完全相同的问题,但它是由安全协议类型硬编码到TLS 1.2引起的,而服务部署到2008服务器没有R2(32位启动,这意味着不可升级到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;

#8


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.

我遇到了同样的问题。这是EndpointAddress的端口地址问题。在Visual Studio中,文件的端口地址(例如Service1.svc)和wcf项目的端口地址必须与您在EndpointAddress中的端口地址相同。让我详细描述一下这个解决方案。

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

    在您的WCF项目中右键单击您的服务文件(例如Service1.svc) - >然后在您的浏览器中选择在浏览器中查看您的网址为http:// localhost:61122 / Service1.svc,现在记下您的端口地址为一个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).

    右键单击您的wcf项目 - >选择属性 - >转到Web选项卡 - >现在服务器部分 - >选择使用Visual Studio开发服务器 - >选择特定端口并提供我们之前从Service1找到的端口地址。服务svc。那是(61122)。

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

早些时候我有不同的端口地址。正确指定端口地址后,我已经给了EndpointAddress,我的问题解决了。

I hope this might be solved your issue.

我希望这可以解决你的问题。

#1


22  

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).

WCF还需要具有传递数据的具体类(因为它都需要是XML可序列化的,并且必须能够以XML模式表示 - 接口不太适合)。

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.

我相信它无法传回IEnumerable - 尝试使用List (或T []数组)或具体类型。

Any luck?

#2


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.

我遇到了同样的问题,因为我从服务器返回了大量的记录,我将以下行添加到我的wcf配置文件中并且它有效。

<system.web>
    <httpRuntime maxRequestLength ="262144" executionTimeout="103600"/>
</system.web>

#3


4  

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

不要将MyClass定义为Serializable。将其标记为[DataContract],将其属性标记为[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.

虽然没有任何固有的阻塞[Serializable]会导致序列化处理的可能性超过其处理能力。

EDIT 2

marc_s's comment got it right

marc_s的评论说得对

#4


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

为了让WCF能够序列化类似的东西

var myClass = new MyClass();
myClass.MyProperty = new B();

#5


0  

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

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

#6


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.

我只是留在这里,万一有人需要它。我遇到了同样的错误。我正在调用我的服务,其服务类型为Dictionary ,其中一个键/值对的字符串值设置为null。 ,string>

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

我更改了代码以确保没有空值并且它有效

#7


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).

刚刚面临完全相同的问题,但它是由安全协议类型硬编码到TLS 1.2引起的,而服务部署到2008服务器没有R2(32位启动,这意味着不可升级到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;

#8


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.

我遇到了同样的问题。这是EndpointAddress的端口地址问题。在Visual Studio中,文件的端口地址(例如Service1.svc)和wcf项目的端口地址必须与您在EndpointAddress中的端口地址相同。让我详细描述一下这个解决方案。

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

    在您的WCF项目中右键单击您的服务文件(例如Service1.svc) - >然后在您的浏览器中选择在浏览器中查看您的网址为http:// localhost:61122 / Service1.svc,现在记下您的端口地址为一个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).

    右键单击您的wcf项目 - >选择属性 - >转到Web选项卡 - >现在服务器部分 - >选择使用Visual Studio开发服务器 - >选择特定端口并提供我们之前从Service1找到的端口地址。服务svc。那是(61122)。

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

早些时候我有不同的端口地址。正确指定端口地址后,我已经给了EndpointAddress,我的问题解决了。

I hope this might be solved your issue.

我希望这可以解决你的问题。