Error “No corresponding start element is open.” when calling a webservice : where to start?

冷暖自知 提交于 2020-01-03 04:34:14

问题


I am consuming a webservice and out of the blue it's suddently failing with the following error:

System.InvalidOperationException was caught
  Message="No corresponding start element is open."
  Source="mscorlib"

The webservice is called correctly and returns a normal response (as checked with fiddler) with valid xml.

I have a hunge I am missing a data element somewhere in my generated soap client but don't know where to start since I can not step into the autogenerated soap client code..

After a few wasted hours I'm hoping someone can help me out on how to start troubleshooting this.. Is there a way I can step into the autogenerated soap client code? Any alternative approach I can take to identify what's wrong?

I'm developing in VS2008 SP1. The autogenerated code has runtime version:2.0.50727.3634

The generated code is in a classlibrary and called from a console app. For service bindings the following was added to the app.config from the console app:

  <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>

And this is my stacktrace of the error:

 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

edit: It seems that it is related to the use of a WCF service reference in stead of the good old Web reference. Somehow the DataContractSerializer is messing up while the XmlSerializer works.


回答1:


Ok, just in case someone else faces the same problem I'm answering my own question here..

The answer to the question "Where / How to start debugging an external webservice" is to add the following to your config file:

   <system.diagnostics>
     <switches>
       <add name="XmlSerialization.Compilation" value="1" />
     </switches>
   </system.diagnostics>


来源:https://stackoverflow.com/questions/13229336/error-no-corresponding-start-element-is-open-when-calling-a-webservice-wher

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!