将协议从 net.tcp 更改为 http、Wcf,出现错误 "No corresponding start element is open"
Changing protocol from net.tcp to http, Wcf, gives me the error "No corresponding start element is open"
我需要将端点从 net.tcp 更新为 http,除一个外,所有端点都工作正常。
客户端web config端配置如下
<endpoint address="http://myseriesservices/Quote.svc" behaviorConfiguration="DynamicTransportBehavior" binding="wsHttpBinding" bindingConfiguration="httpConfiguration" contract="EbqQuoteServiceReference.IQuote" name="Quote" />
<!--<endpoint address="net.tcp://myseriesservices/Quote.svc" behaviorConfiguration="DynamicTransportBehavior" binding="netTcpBinding" bindingConfiguration="Quote" contract="EbqQuoteServiceReference.IQuote" name="Quote" />-->
和 wsHttpBinding
<wsHttpBinding>
<binding name="httpConfiguration" maxReceivedMessageSize="10485760" openTimeout="00:01:00" receiveTimeout="00:05:00" sendTimeout="00:05:00">
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
这是服务器端的配置。
<service behaviorConfiguration="MexBehavior" name="OM.Mec.BF.Ebq.Quote">
<endpoint address="" bindingConfiguration="BasicHttpBinding_Large" name="BasicHttpBinding_Large" binding="wsHttpBinding" contract="OM.Mec.SC.Ebq.IQuote" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<!--<endpoint address="" bindingConfiguration="NetTcp_StreamingResponse" name="Quote" binding="netTcpBinding" contract="OM.Mec.SC.Ebq.IQuote" />
<endpoint address="Mex" binding="mexTcpBinding" bindingConfiguration="" name="QuoteService.MexBinding" contract="IMetadataExchange" />-->
<host>
<baseAddresses>
<add baseAddress="http://myseriesservices/Quote.svc" />
<!--<add baseAddress="net.tcp://myseriesservices/Quote.svc" />-->
</baseAddresses>
</host>
</service>
和BasicHttpBinding_Large
<binding name="BasicHttpBinding_Large" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
出现此错误的原因可能是什么?
我在后端进行了调试,成功地调用了数据库,但在将数据返回给客户端时却失败了。 net.tcp 如果没问题,它只会因 http
而失败
您是通过什么方式托管服务的?如果是IIS,我们不应该在配置中添加基地址,因为我们应该在IIS站点绑定模块中添加基地址。
此外,似乎服务器和客户端之间的绑定配置不一致。
我建议您通过使用添加服务引用来生成客户端代理 class 在客户端调用服务,如下所示。
可以保持客户端和服务端绑定配置的一致性。
如果问题仍然存在,请随时告诉我。
此错误可能是以下原因之一
- 我认为您的调用失败是由于您从服务中 return 的对象的大小。
- 第二个原因可能是您的服务的序列化设置,因为 Net TCP (BinarySerializer) 和 HTTP (DatacontractSerializer) 绑定默认使用不同的序列化。
大响应的解决方案会将您的响应分成块并通过 HTTP 发送。你可以参考这个 link https://docs.microsoft.com/en-us/dotnet/framework/wcf/samples/chunking-channel
我需要将端点从 net.tcp 更新为 http,除一个外,所有端点都工作正常。
客户端web config端配置如下
<endpoint address="http://myseriesservices/Quote.svc" behaviorConfiguration="DynamicTransportBehavior" binding="wsHttpBinding" bindingConfiguration="httpConfiguration" contract="EbqQuoteServiceReference.IQuote" name="Quote" />
<!--<endpoint address="net.tcp://myseriesservices/Quote.svc" behaviorConfiguration="DynamicTransportBehavior" binding="netTcpBinding" bindingConfiguration="Quote" contract="EbqQuoteServiceReference.IQuote" name="Quote" />-->
和 wsHttpBinding
<wsHttpBinding>
<binding name="httpConfiguration" maxReceivedMessageSize="10485760" openTimeout="00:01:00" receiveTimeout="00:05:00" sendTimeout="00:05:00">
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
这是服务器端的配置。
<service behaviorConfiguration="MexBehavior" name="OM.Mec.BF.Ebq.Quote">
<endpoint address="" bindingConfiguration="BasicHttpBinding_Large" name="BasicHttpBinding_Large" binding="wsHttpBinding" contract="OM.Mec.SC.Ebq.IQuote" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<!--<endpoint address="" bindingConfiguration="NetTcp_StreamingResponse" name="Quote" binding="netTcpBinding" contract="OM.Mec.SC.Ebq.IQuote" />
<endpoint address="Mex" binding="mexTcpBinding" bindingConfiguration="" name="QuoteService.MexBinding" contract="IMetadataExchange" />-->
<host>
<baseAddresses>
<add baseAddress="http://myseriesservices/Quote.svc" />
<!--<add baseAddress="net.tcp://myseriesservices/Quote.svc" />-->
</baseAddresses>
</host>
</service>
和BasicHttpBinding_Large
<binding name="BasicHttpBinding_Large" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
出现此错误的原因可能是什么? 我在后端进行了调试,成功地调用了数据库,但在将数据返回给客户端时却失败了。 net.tcp 如果没问题,它只会因 http
而失败您是通过什么方式托管服务的?如果是IIS,我们不应该在配置中添加基地址,因为我们应该在IIS站点绑定模块中添加基地址。
此外,似乎服务器和客户端之间的绑定配置不一致。
我建议您通过使用添加服务引用来生成客户端代理 class 在客户端调用服务,如下所示。
可以保持客户端和服务端绑定配置的一致性。
如果问题仍然存在,请随时告诉我。
此错误可能是以下原因之一
- 我认为您的调用失败是由于您从服务中 return 的对象的大小。
- 第二个原因可能是您的服务的序列化设置,因为 Net TCP (BinarySerializer) 和 HTTP (DatacontractSerializer) 绑定默认使用不同的序列化。
大响应的解决方案会将您的响应分成块并通过 HTTP 发送。你可以参考这个 link https://docs.microsoft.com/en-us/dotnet/framework/wcf/samples/chunking-channel