我有這個很奇怪的錯誤...WCF錯誤 - 連接被遠程主機關閉
我正在開發一個WCF服務,我從其他人那裏接管了。有這樣定義的類稱爲用戶:
namespace WebApi.DataContracts
{
[DataContract]
public class User
{
[DataMember]
public int Id
{
get;
set;
}
[DataMember]
public string Username
{
set;
get;
}
...
[DataMember]
public DateTime Birth
{
get;
set;
}
[DataMember]
public bool Newsletter
{
get;
set;
}
等等
我做了一個API方法,返回此對象作爲數據
namespace WebApi
{
public class SoapApi : IApi
{
public DataContracts.User UserRegister()
{
DataContracts.User u = new DataContracts.User();
return u;
}
}
當我嘗試從客戶端調用這個,我得到這個錯誤:
[SocketException (0x2746): An existing connection was forcibly closed by the remote host]
System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +6132200
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +134
[IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.]
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +300
System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size) +26
System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead) +265
[WebException: The underlying connection was closed: An unexpected error occurred on a receive.]
System.Net.HttpWebRequest.GetResponse() +6038435
ClassLib.HandlerFactory.AjaxProxy.ProcessRequest(HttpContext context) in ClassLib\HandlerFactory.cs:75
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
在我看來,這個線
System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +6132200
表明,試圖發送可怕的大量字節 - 爲什麼是這樣?
更新:在我的客戶的web.config結合如下:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_Api" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<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>
<binding name="ApiBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<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>
</basicHttpBinding>
</bindings>
服務器的web.config綁定是:
<bindings>
<basicHttpBinding>
<binding name="ApiBinding" />
</basicHttpBinding>
<webHttpBinding>
<binding name="ApiBinding" />
</webHttpBinding>
</bindings>
/卡斯滕
你的裝訂我的朋友是什麼?你能告訴我們嗎?什麼是安全? – Aliostad 2011-05-03 10:47:53
我現在在問題文本的底部添加了web.config中的綁定。謝謝 – 2011-05-03 11:30:07
任何想法?我試圖返回簡單的類型 - 例如。一個int - 並且工作正常。 – 2011-05-03 13:13:32