- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我自己托管 WCF 服务。当我通过客户端调用我的 GetProject() 方法时,我得到一个 Unhandled CommuncationException 和一个 InnerException
"The underlying connection was closed: An unexpected error occurred on a receive."
"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.Reply(MessageRpc& rpc)System.Runtime.Serialization.SerializationException: Type 'System.FormatException' with data contract name 'FormatException:http://schemas.datacontract.org/2004/07/System' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
ServiceContract
我有以下几点:
[OperationContract]
Project GetProject(int id);
KnownTypeAttribute
使用。在此处注释以反射(reflect)更改。
[DataContract]
//[KnownType(typeof(Contact))]
//[KnownType(typeof(ProjectDetails))]
//[KnownType(typeof(CommercialEntity))]
public class Project
{
[DataMember]
public ProjectDetails details = new ProjectDetails();
[DataMember]
public List<Contact> contacts = new List<Contact>();
[DataMember]
public List<CommercialEntity> POs = new List<CommercialEntity>();
[DataMember]
public List<CommercialEntity> invoices = new List<CommercialEntity>();
[DataMember]
public List<CommercialEntity> quotes = new List<CommercialEntity>();
[DataMember]
public List<CommercialEntity> CRs = new List<CommercialEntity>();
}
[DataContract]
public class ProjectDetails
{
[DataMember]
public int projectId { get; set; }
[DataMember]
public string name { get; set; }
[DataMember]
public int calYearId { get; set; }
[DataMember]
public string projectState { get; set; }
[DataMember]
public string reportTitle { get; set; }
[DataMember]
public int plantId { get; set; }
[DataMember]
public string holdNumber { get; set; }
[DataMember]
public string holdDescription { get; set; }
[DataMember]
public string remarks { get; set; }
[DataMember]
public string adminComments {get; set; }
[DataMember]
public int companyId { get; set; }
[DataMember]
public int customerId { get; set; }
[DataMember]
public string folderNumber { get; set; }
[DataMember]
public int invoicedInFull { get; set; }
[DataMember]
public int approved { get; set; }
}
}
[DataContract]
public class CommercialEntity
{
[DataMember]
public string number { get; set; }
[DataMember]
public DateTime date { get; set; }
[DataMember]
public string comments { get; set; }
public CommercialEntity(string setNumber, DateTime setDate, string setComments)
{
number = setNumber;
date = setDate;
comments = setComments;
}
}
[DataContract]
public class Contact
{
[DataMember]
public string firstName { get; set; }
[DataMember]
public string lastName { get; set; }
[DataMember]
public string emailAddress { get; set; }
[DataMember]
public string phoneNumber { get; set; }
[DataMember]
public int alert { get; set; }
[DataMember]
public int projectLead { get; set; }
[DataMember]
public int mainContact { get; set; }
public Contact(string first, string last, string email, string phone, int alrt, int projLead, int mainCntct)
{
firstName = first;
lastName = last;
emailAddress = email;
phoneNumber = phone;
alert = alrt;
projectLead = projLead;
mainContact = mainCntct;
}
public Contact() { }
}
See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.
***** Exception Text *******
System.ServiceModel.CommunicationException: An error occurred while receiving the HTTP response to myInternalIP:myPort/ProjectService/ProjectService. 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. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
--- End of inner exception stack trace ---
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at IProjectService.GetQuerytoList(Int32 id)
at ProjectServiceClient.GetQuerytoList(Int32 id) in C:\Users\drwill\documents\visual studio 2010\Projects\ProjectBaseWCF\ProjectBase\generatedProxy.cs:line 1065
at ProjectWCFClient.MainForm.openToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Users\drwill\documents\visual studio 2010\Projects\ProjectBaseWCF\ProjectBase\PBMain.cs:line 961at ProjectWCFClient.MainForm.ProjectListBox_DoubleClick(Object sender, EventArgs e) in C:\Users\drwill\documents\visual studio 2010\Projects\ProjectBaseWCF\ProjectBase\PBMain.cs:line 55
at System.Windows.Forms.Control.OnDoubleClick(EventArgs e)
at System.Windows.Forms.ListBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IProjectService" maxReceivedMessageSize="500000000" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://192.168.0.99:9000/ProjectService/ProjectService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IProjectService"
contract="IProjectService" name="BasicHttpBinding_IProjectService" />
</client>
</system.serviceModel>
</configuration>
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service behaviorConfiguration="ProjectBaseWCFServiceLib.Service1Behavior" name="ProjectBaseWCFServiceLib.ProjectService">
<endpoint address="" binding="basicHttpBinding" contract="ProjectBaseWCFServiceLib.IProjectService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/ProjectBaseWCFServiceLib/Service1/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ProjectBaseWCFServiceLib.Service1Behavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
BasicHttpBinding binding = new BasicHttpBinding();
binding.OpenTimeout = new TimeSpan(0, 10, 0);
binding.CloseTimeout = new TimeSpan(0, 10, 0);
binding.SendTimeout = new TimeSpan(0, 10, 0);
binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
binding.MaxReceivedMessageSize = 500000000;
binding.MaxBufferSize = 500000000;
binding.MaxBufferPoolSize = 500000000;
selfHost.AddServiceEndpoint(typeof(IProjectService), binding, "ProjectService");
最佳答案
好的。所以这有点晚了,但它是这样的:System.FormatException
被抛出的原因是发生了 int.Parse("0")
内GetProject(int id)
我调用它时的方法。
所以我改变了处理 "0"
的方法案例通过调用更强大的 Convert.ToInt32("0")
.
我认为这里学到的教训是你应该首先确保你正在执行的方法有效。只有到那时,您才应该开始询问 DataContractSerializer
不足以序列化您的类型。
关于c# - WCF 方法抛出 SerializationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16698349/
下面的简单类继承自 HashSet,因此必须实现 ISerialization 成员(以非标准方式)。当我尝试序列化然后反序列化 Group 的实例时,出现以下异常: Test method Util
我只是创建了最简单的 Singleton EJB 来返回自定义可序列化对象,但是当我调用远程方法时出现以下异常: org.jboss.serial.exception.SerializationExc
我的 web api 项目中有一个 Report 类: [KnownType(typeof(Employee))] [DataContract] public class Report { [
我的程序在加载序列化文件的部分遇到问题。如果文件无法反序列化,我想很好地失败,但由于某种原因,我的程序将中断而不是进入 catch 子句。这是我的代码 using (FileStream fs = n
由于我之前的问题 ( XML serialization of interfaces ) 我得到了另一个问题... 我有一个从数据库导出数据的应用程序。导出过程由实现用于调用的通用接口(interfa
早上好,我有一个 TCP 服务器和一个 TCP 客户端。这是服务器的代码: public static class Server { private static IPEndPoint end
当反序列化带有 EnumMemberAttribute 且值包含空格的标记枚举时,将抛出 SerializationException。值中的空格被视为分隔符。 有没有办法更改分隔符或将值放在引号中?
我创建了在 Selenium 中初始化 Chrome Webdriver 的 NUnit 套件。这适用于 InternetExplorer 驱动程序和 Firefox 驱动程序,但每次我尝试使用 Ch
所以我自己托管 WCF 服务。当我通过客户端调用我的 GetProject() 方法时,我得到一个 Unhandled CommuncationException 和一个 InnerException
我得到一个: System.Runtime.Serialization.SerializationException: Unable to find assembly 'myNameSpace, Ve
我正在编写一个通用过滤器类,主要用于从人群中过滤人员。我正在尝试序列化过滤器类,但在运行时我得到一个 SerializationException: System.Runtime.Serializat
目前我正在使用 LibGDX 的 JSON 输出文件编写类来处理游戏的数据保存(和加载)部分。我一直在谷歌上试图找到解决方案,并且已经接近,但没有雪茄。到目前为止,我已经成功地尝试保存 Array到文
我有以下类(class): import lombok.Data; import java.io.Serializable; @Data public class Person implements
我得到SerializationException经过时ArrayList作为 RPC servlet 方法的参数。类 MyObject仅包含 2 个类型为 String 的字段和Serializab
给定以下代码, [DataContract] public class TestClass { [DataMember] public object _TestVariable; publ
在尝试反序列化一个相对较大的对象图时,我看到了奇怪的行为 ~10000 行,上面有 6 列。我确定问题是在尝试将此数组从服务反序列化回客户端时出现序列化异常。它适用于少于 9000 个对象的数据集,并
我有一个 Windows 服务,它在运行时在另一个 AppDomain 中加载程序集。然后执行它们并最终卸载 AppDomain。问题是插件的执行方法是异步任务,我得到了 SerializationE
我开始尝试 Apache Pivot,因为我想使用 XML 创建 Java GUI。 我关注了他们的Hello BXML tutorial在他们的网站上使用 Maven 项目。 这些是我正在使用的文件
尝试通过 WebApi get 返回列表时出现 SerializationException。 Full error message on pastebin 这是我的代码: HomeControlle
我在 Spring 框架 (4.1.6) 上有应用程序,使用 Spring Security 4.0.1。我在应用程序中使用了@EnableRedisHttpSession 和@EnableSprin
我是一名优秀的程序员,十分优秀!