System.ServiceModel.CommunicationException

System.ServiceModel.CommunicationException

提问人:ora 提问时间:7/8/2021 最后编辑:ora 更新时间:7/12/2021 访问量:218

问:

我正在使用 WCF 客户端服务器。WCF 服务器安装在终端服务器上。当我在本地测试它时,一切都适用于本地 WCF 服务器。

An unhandled exception of type 'System.ServiceModel.CommunicationException' occurred in mscorlib.dll
Fehler beim Deserialisieren des Textkörpers der Antwortnachricht für Vorgang "MixGas". Es wurde das Endelement "MixGasResult" aus Namespace "http://tempuri.org/" erwartet. Gefunden wurde "Element "b:GasMatrice" aus Namespace "http://schemas.datacontract.org/2004/07/RadaxPpdsLibrary"".


Unbehandelte Ausnahme: System.ServiceModel.CommunicationException: Fehler beim Deserialisieren des Textkörpers der Antwortnachricht für Vorgang "MixGas". Es wurde das Endelement "MixGasResult" aus Namespace "http://tempuri.org/" erwartet. Gefunden wurde "Element "b:GasMatrice" aus Namespace "http://schemas.datacontract.org/2004/07/RadaxPpdsLibrary"". ---> System.Xml.XmlException: Es wurde das Endelement "MixGasResult" aus Namespace "http://tempuri.org/" erwartet. Gefunden wurde "Element "b:GasMatrice" aus Namespace "http://schemas.datacontract.org/2004/07/RadaxPpdsLibrary"".
   bei System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
   bei System.Xml.XmlExceptionHelper.ThrowEndElementExpected(XmlDictionaryReader reader, String localName, String ns)
   bei System.Xml.XmlBaseReader.ReadEndElement()
   bei System.Xml.XmlBaseReader.ReadElementContentAsString()
   bei System.Xml.XmlBinaryReader.ReadElementContentAsString()
   bei System.ServiceModel.Dispatcher.PrimitiveOperationFormatter.DeserializeResponse(XmlDictionaryReader reader, Object[] parameters)
   bei System.ServiceModel.Dispatcher.PrimitiveOperationFormatter.DeserializeReply(Message message, Object[] parameters)
   --- Ende der internen Ausnahmestapelüberwachung ---

我不知道我该怎么办。 调用如下:

   public string MixGas(double incomingMassFlow, string incomingGasInp, double sideMassFlow, string sideGasInp,
        out double outgoingMassFlow, out string outgoingGasInp)
    {
        var result = Channel.MixGas(incomingMassFlow, incomingGasInp, sideMassFlow, sideGasInp,
            out outgoingMassFlow, out outgoingGasInp);

        return result;

    }

方法 Channel.MixGas 引发此异常。 我正在使用其他服务器方法,没有任何例外。

此服务器配置文件为:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="All"
              propagateActivity="true">
        <listeners>
          <add name="traceListener"
               type="System.Diagnostics.XmlWriterTraceListener"
               initializeData= "Traces.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
</configuration>

这是 C# 中的服务器配置:

   serviceHost = new ServiceHost(typeof(RadaxPpdsServerLibrary.RadaxPpdsService));

     var binding = new NetTcpBinding()
    {
        OpenTimeout = new TimeSpan(0, 10, 0),
        CloseTimeout = new TimeSpan(0, 10, 0),
        SendTimeout = new TimeSpan(0, 10, 0),
        ReceiveTimeout = new TimeSpan(0, 10, 0),
        MaxReceivedMessageSize = 1000000,
        MaxBufferSize = 1000000,
        MaxConnections = 100,
        Security =
        {
            Mode = SecurityMode.None,
        }
         // PortSharingEnabled = true
     };

    serviceHost.AddServiceEndpoint(typeof(IRadaxPpdsService), binding, "net.tcp://localhost:60000/RadaxPpdsService/RadaxPpdsEndpoint");
WCF公司 例外

评论

0赞 Theobald Du 7/9/2021
启用 wcf 跟踪以查找内部异常并查看特定错误消息。以下是启用 wcf 跟踪的参考: stackoverflow.com/questions/4271517/how-to-turn-on-wcf-tracing
0赞 ora 7/12/2021
我现在添加了这种跟踪方法,我很困惑。我在 error.svclog 中收到 erorr 套接字连接已中止。这可能是由于处理消息时出错或远程主机超过接收超时或基础网络资源问题导致的。本地套接字超时为“10675199.02:48:05.4775807”。但客户没有提出任何异常。
0赞 ora 7/12/2021
添加 MaxBufferSize = 1000000 后,客户端的套接字连接中止已消失。System.ServiceModel.CommunicationException 错误仍然存在。
0赞 Theobald Du 7/14/2021
增加 <serviceBehaviors> 中 maxItemsInObjectGraph 的大小。
0赞 ora 7/21/2021
它现在可以工作了,我已经明确地将 maxItemsInObjectGraph 2147483647。它有效。谢谢。

答:

0赞 sina ajilyan 7/11/2021 #1

如果你发布你的配置文件,那就太好了,没有你的配置文件,很难找到问题。

评论

0赞 ora 7/12/2021
谢谢你的回答,我已经添加了配置文件。