- 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/
来自 java docs 公共(public) FileWriter(String fileName) 抛出 IOException 抛出: IOException - 如果指定的文件存在但它是目录而
我使用以下代码将我的 .net 客户端(基于 CQL)连接到 3 节点 Cassandra 集群。我以 30 条记录/秒的速度(从 RabbitMQ)获取数据,并且它们顺利地存储在 cassandra
如果在读取文件时缺少字段,我应该捕获 NoSuchElementException。如果缺少一个字段,我只需要跳到文件的下一行。我的问题是,我在哪里实现我的 try/catch 代码来做到这一点?这是
我正在尝试使用 ASP.NET MVC 实现 OpeinID 登录。我正在尝试按照 http://blog.nerdbank.net/2008/04/add-openid-login-support-
学习使用 Java 进行 xml 解析,并且正在编写一个测试程序来尝试各种东西。所有测试 System.out.println() 都是我在控制台中所期望的,除了 childElement 返回 [n
我正在尝试使用 SwingUtilities 创建 JFrame Thread tt = new Thread(new Runnable() { public void run
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我写了这段代码: MethodInfo method2 = typeof(IntPtr).GetMethod( "op_Explicit", Bind
我开始学习 Java,并且正在根据书本做一些练习。在执行此操作时,我遇到了以下错误:线程“main”java.util.InputMismatchException 中出现异常。我正在编写一个简单的程
我有一个文本文件,其中前两行是整数 m 和 n,然后有 m 行,每行都有 n 管道分隔值。我编写了一个程序,读取文件并使用文件中的值创建 m*n 数组,它工作了无数次,然后突然,使用相同的代码,使用相
所以我尝试使用在另一个类中生成的 bean 以在主应用程序中使用 package com.simon.spring.basics.properties; import org.spri
我还没有完成这个应用程序,但我希望在我的手机上看到它的样子。但是,它会强制关闭并引发 InstantiationException。 logcat 异常: 09-19 20:13:47.987: D/
我想从 UIViewController 加载一个基于 SwiftUI 的 View ,该 View 读取包本地的 json。仅 swiftUI 项目中的代码和绑定(bind)工作正常,当我利用 UI
'java.net.SocketTimeoutException:连接超时' 循环一段时间后我收到此错误。为什么我会收到 SocketTimeoutException?我该如何修复这个错误? @Ove
当有 null 值时抛出 ArgumentNullException() 是个好主意吗? This thread 没有提到在 null 上抛出的最明显的异常。 谢谢 最佳答案 ArgumentNull
我得到这个异常: NullReferenceException Object reference not set to an instance of an object at Namespace
所以其中一个方法的描述如下: public BasicLinkedList addToFront(T data) This operation is invalid for a sorted list
我正在使用 Intellij Idea,当我去生成 JavaDocs(通过工具 -> 生成 JavaDoc)时,我抛出了一个 IllegealArgumentException,没有关于发生了什么问题
我正在学习 C++ 中的互斥锁,但以下代码(摘自 N. Josuttis 的“C++ 标准库”)有问题。 我不明白为什么它会阻塞/抛出除非我在主线程中添加this_thread::sleep_for(
我正在试验 JavaFX 标签和组,通过鼠标拖动将它们移动到屏幕上。新节点从一些线程添加到动画组。但是,有时我会突然看到以下异常 - 我假设,当某些节点重叠时。但是不知道是什么问题……因为不涉及我的代
我是一名优秀的程序员,十分优秀!