这可能是由于服务端点绑定没有使用 HTTP 协议

我在本地机器上有一个正常运行的 WCF 服务。我把它放在服务器上,接收到如下错误:

接收。在接收 HTTP 响应 Http://xx.xx.x.xx:8200/services/wcfclient.svc. 这可能是服务的缘故 不使用 HTTP 的端点绑定 这也可能是由于 中止 HTTP 请求上下文 服务器(可能是由于 服务关闭)。请参阅服务器 更多细节。]

我已经在网址服务,它是正常工作。我为函数所做的就是返回一个字符串到一个图像名,所以传递的数据并不多。我追踪了日志,它给了我同样的信息。下面是我的客户端配置:

<binding name="basicHttpBinding_IWCFClient" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<endpoint name="basicHttpBinding_IWCFClient"
address="http://localhost:4295/Services/WCFClient.svc"
binding="basicHttpBinding"
bindingConfiguration="basicHttpBinding_IWCFClient"
behaviorConfiguration="WCFGraphicManagementTool.Services.ClientBehavior"
contract="WCFClient.IWCFClient" />

下面是我的服务器配置:

<service behaviorConfiguration="WCFGraphicManagementTool.Services.WCFClientBehavior"
name="WCFGraphicManagementTool.Services.WCFClient">
<endpoint name="basicHttpBinding_IWCFClient"
address=""
binding="basicHttpBinding"
contract="WCFGraphicManagementTool.Contracts.IWCFClient" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
<behavior name="WCFGraphicManagementTool.Services.WCFClientBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceThrottling maxConcurrentCalls="120" maxConcurrentSessions="120"
maxConcurrentInstances="120" />
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>

它是否是服务器上的一个设置,因为它可以在我的本地计算机上工作?

200939 次浏览

I figured out the problem. It ended up being a path to my config file was wrong. The errors for WCF are so helpful sometimes.

I've had this same error and the problem was serialization. I managed to find the real problem using Service Trace Viewer http://msdn.microsoft.com/en-us/library/ms732023.aspx and solved it easy. Maybe this will help someone.

I had this problem "This could be due to the service endpoint binding not using the HTTP protocol" and the WCF service would shut down (in a development machine)

I figured out: in my case, the problem was because of Enums,

I solved using this

    [DataContract]
[Flags]
public enum Fruits
{
[EnumMember]
APPLE = 1,
[EnumMember]
BALL = 2,
[EnumMember]
ORANGE = 3


}

I had to decorate my Enums with DataContract, Flags and all each of the enum member with EnumMember attributes.

I solved this after looking at this msdn Reference:

I think there is serialization problem, you can find exact error just need to add below code in service config in <configuration> section.

After config update "App_tracelog.svclog" file will create, where your service exist just need to open .svclog file and find red color line on left side panel which is error and see its description for more info.

I hope this will help to find your error.

<configuration>
...
...


<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
<listeners>
<add name="ServiceModelTraceListener" />
</listeners>
</source>
<source name="System.ServiceModel" switchValue="Verbose,ActivityTracing">
<listeners>
<add name="ServiceModelTraceListener" />
</listeners>
</source>
<source name="System.Runtime.Serialization" switchValue="Verbose,ActivityTracing">
<listeners>
<add name="ServiceModelTraceListener" />
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="App_tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp" />
</sharedListeners>
</system.diagnostics>


</configuration>

Update: If you will not able to find updated "App_tracelog.svclog" file then please find "<some GUID>App_tracelog.svclog" like "a39e3026-5dd8-4d39-842a-04d486615eedApp_tracelog.svclog"

Solution with DataContract, Flags for Enums looks a bit ugly. In my case problem been solved by adding something like "NotSet = 0" into enum:

public enum Fruits
{
UNKNOWN = 0,
APPLE = 1,
BALL = 2,
ORANGE = 3
}

I've seen this error caused by a circular reference in the object graph. Including a pointer to the parent object from a child will cause the serializer to loop, and ultimately exceed the maximum message size.

My problem was, that return type of my service was string. But I returned string of type xml:

<reponse><state>1</state><message>Operation was successfull</message</response>

so error was thrown.

This error can be because of contract mismatch. Consider the three layered application below...

UI Layer
|
Process Layer
|
Data Access Layer
-> Contract Between Process and UI layer has the same enum with missing (Onhold = 3). Enum: Start = 1, Stop = 2. -> Contract Between Data Access And Process layer has enum Enum: Start = 1,Stop = 2,Onhold = 3.

In this case we will get the same error in process layer response.

The same error comes in other contract mismatch in multilayered application.

I had this problem because I configured my WCF Service to return a System.Data.DataTable.

It worked fine in my test HTML page, but blew up when I put this in my Windows Form application.

I had to go in and change the Service's Operational Contract signature from DataTable to DataSet and return the data accordingly.

If you have this problem, you may want to add an additional Operational Contract to your Service so you do not have to worry about breaking code that rely on existing Services.

This could be due to many reasons; below are few of those:

  1. If you are using complex data contract objects(that means custom object with more child custom objects), make sure you have all the custom objects decorated with DataContract and DataMember attributes
  2. If your data contract objects use inheritance, make sure all base classes has the DataContract and DataMember attributes. Also, you need to have the base classes specify the derived classes with the [KnownType(typeof(BaseClassType))] attribute ( check out more info here on this).

  3. Make sure all your data contract object properties have both get and set properties.

My problem was too many items were being passed between client and server. I had to change this settings in the behavior on both sides.

<dataContractSerializer maxItemsInObjectGraph="2147483646"/>

In my instance, the error was generated because one of my complex types had a property with no set method.

The serializer threw an exception because of that fact. Added internal set methods and it all worked fine.

Best way to find out why this is happening (in my opinion) is to enable trace logging.

I achieved this by adding the following section to my web.config:

<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging" switchValue="Warning,ActivityTracing">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\log\Traces.svclog" />
<add type="System.Diagnostics.DefaultTraceListener" name="Default" />
</listeners>
</source>
<source propagateActivity="true" name="System.ServiceModel" switchValue="Verbose,ActivityTracing">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\log\Traces.svclog" />
<add type="System.Diagnostics.DefaultTraceListener" name="Default" />
</listeners>
</source>
</sources>
<trace autoflush="true" />
</system.diagnostics>

Once set, I ran my client, got exception and checked the 'Traces.svclog' file. From there, I only needed to find the exception.

This might not be relevant to your specific problem, but the error message you mentioned has many causes, one of them is using a return type for an [OperationContract] that is either abstract, interface, or not known to the WCF client code.

Check the post (and solution) below

https://stackoverflow.com/a/5310951/74138

I think the best way to solve this is to follow the error advice, hence looking for server logs. To enable logs I added

 <system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
<listeners>
<add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\logs\TracesServ_ce.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>

Then you go to c:\logs\TracesServ_ce.svclog open it with microsoft service trace viewer. And see what the problem really is.

For more insight into this issue, also see: An existing connection was forcibly closed by the remote host - WCF

My problem ended up being that my data transfer objects were too complex. Start withsimple properties like public long Id { get; set; } and once you get that working than start adding additional stuff as needed.

I struggled with this for a couple of days and tried every answer from this post and many others and share my solution because symptoms were the same but the problem was different.

The problem was that the app pool was configured with a memory limit and it just get recycled after a variable period of time.

Hope this helps somebody else!
Greetings,

in my case

my service has function to download Files

and this error only shown up on trying to download Big Files

so I found this answer to Increase maxRequestLength to needed value in web.config

I know that's weird, but problem solved

if you don't make any upload or download operations maybe this answer will not help you

Also had this issue and it was due to forgetting to decorate my model with DataContract and DataMember attributes

For me the solutions of this Error very strange. 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.

I was facing the same issue and solved with below code. (if any TLS connectivity issue)

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

Please paste this line before open the client channel.

If you have a database(working in visual studio), make sure there are no foreign keys in the tables, I had foreign keys and it gave me this error and when I removed them it ran smoothly

I realize there are seemingly many "solutions" to this problem. I was experiencing this same error message in a VB.NET application that was making a call to a wsdl. The framework that I published the application under was 3.5, and IT recently disabled TLS 1.0 and 1.1 on my application server that was running the app as a schedule task.

Targeting the application framework to 4.5.2 resolved this issue for me.

I had this issue, mine was web application binding to a web service. The web service was hosted on a server with SSL certificates and using http while the web application was using http. I just changed the binding in the webconfig of the web application to communicate to the webservice using https. Hope it helps

 <binding name="XXXXSoap" closeTimeout="00:50:00" openTimeout="00:40:00" receiveTimeout="00:20:00" sendTimeout="00:40:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxBufferSize="65536" maxReceivedMessageSize="65536" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true" messageEncoding="Text">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
</security>
</binding>

then the endpoint:

<endpoint address="https://ipaddress:port/xxxx.asmx" binding="basicHttpBinding" bindingConfiguration="XXXXSoap" contract="xxxxSoap" name="XXXXSoap" />