可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have a WCF Service running fine on my local machine. I put it on the servers, and I am receiving the following error:
An error occurred while receiving the
HTTP response to
http://xx.xx.x.xx:8200/Services/WCFClient.svc.
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.]
I have gone to the service in the url and it is working correctly. All I am doing for the function is returning a string to an image name, so the data being passed isn't a lot. I have traced the log and it gives me the same information. Here is my client config:
<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" />
Here is my server config:
<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>
Would it be a setting on the server since it works on my local machine?
回答1:
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.
<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>
回答2:
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:
回答3:
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.
回答4:
In my instance, the error was generated because one of my complex types had a property with no set method.
The serializer threw and 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.
回答5:
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
}
回答6:
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.
回答7:
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.
回答8:
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.
回答9:
This could be due to many reasons; below are few of those:
- 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
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).
Make sure all your data contract object properties have both get and set properties.
回答10:
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"/>
回答11:
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.
回答12:
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.
回答13:
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.
回答14:
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.
回答15:
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
回答16:
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.
回答17:
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,
回答18:
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
回答19:
Also had this issue and it was due to forgetting to decorate my model with DataContract and DataMember attributes
回答20:
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.
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
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.
回答21:
To fix this, we had to changed the AppPool Identity to an administrator account.