错误“没有打开相应的开始元素".调用网络服务时:从哪里开始? [英] Error "No corresponding start element is open." when calling a webservice : where to start?

查看:82
本文介绍了错误“没有打开相应的开始元素".调用网络服务时:从哪里开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个Web服务,但是突然出现了以下错误:

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"

该Web服务被正确调用,并返回带有有效xml的正常响应(由fiddler检查).

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

我很饿,我在生成的Soap客户端中某处缺少数据元素,但不知道从哪里开始,因为我无法进入自动生成的Soap客户端代码.

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

几个小时后,我希望有人能帮助我解决如何开始解决此问题.有没有办法进入自动生成的soap客户端代码?我可以采取其他任何方法来找出问题所在吗?

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?

我正在VS2008 SP1中进行开发.自动生成的代码具有运行时版本:2.0.50727.3634

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

生成的代码在类库中,并从控制台应用程序中调用.对于服务绑定,以下内容已从控制台应用程序添加到app.config:

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

修改:似乎与WCF服务引用的使用有关,而不是与旧的Web参考有关.XmlSerializer工作时,DataContractSerializer有点混乱.

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.

推荐答案

好,以防万一有人遇到相同的问题,我在这里回答自己的问题.

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

在哪里/如何开始调试外部Web服务"问题的答案是将以下内容添加到您的配置文件中:

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>

这篇关于错误“没有打开相应的开始元素".调用网络服务时:从哪里开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆