我正在使用一个网络服务,它突然失败并出现以下错误:
System.InvalidOperationException was caught
Message="No corresponding start element is open."
Source="mscorlib"
正确调用 Web 服务并返回带有有效 xml 的正常响应(与 fiddler 一起检查)。
我有一个巨大的问题,我在生成的soap客户端的某个地方丢失了一个数据元素,但不知道从哪里开始,因为我无法进入自动生成的soap客户端代码。
浪费了几个小时后,我希望有人能帮助我解决如何开始解决这个问题。有没有办法可以进入自动生成的肥皂客户端代码? 我可以采取任何替代方法来确定问题所在?
我正在开发 VS2008 SP1。自动生成的代码具有运行时版本:2.0.50727.3634
生成的代码位于类库中,并从控制台应用程序调用。对于服务绑定,以下内容已从控制台应用程序添加到 app.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="OrderServiceSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.acdc.com/services/order.asmx"
binding="basicHttpBinding" bindingConfiguration="OrderServiceSoap"
contract="MLOrderServiceReference.OrderServiceSoap" name="OrderServiceSoap" />
</client>
</system.serviceModel>
这是我的错误堆栈跟踪:
System.InvalidOperationException was caught
Message="No corresponding start element is open."
Source="mscorlib"
StackTrace:
Server stack trace:
at System.Xml.XmlBaseReader.ReadEndElement()
at System.ServiceModel.Channels.Message.ReadFromBodyContentsToEnd(XmlDictionaryReader reader, EnvelopeVersion envelopeVersion)
at System.ServiceModel.Channels.Message.ReadFromBodyContentsToEnd(XmlDictionaryReader reader)
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)\r\n\r\nException 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 DS.ACDC.AppService.MLOrderServiceReference.OrderServiceSoap.GetOrderDetail(Int32 ClientId, Int32 OrderId)
at DS.ACDC.AppService.MLOrderServiceReference.OrderServiceSoapClient.GetOrderDetail(Int32 ClientId, Int32 OrderId) in C:\\localdata\\ML\\ACDC\\DS.ACDC.AppService\\Service References\\MLOrderServiceReference\\Reference.cs:line 4151
at DS.ACDC.AppService.OrderService.getOrder(CISmapping CISdetails) in C:\\localdata\\ML\\ACDC\\DS.ACDC.AppService\\OrderService.cs:line 123
编辑: 似乎它与使用 WCF 服务参考而不是旧的 Web 参考有关。不知何故 DataContractSerializer 在 XmlSerializer 工作时搞砸了。