如何解决在VS 2008中调用“更新服务参考”时,如何绕过WCF服务的操作合同限制
| 我在应用程序中只有一个Wcf服务时遇到麻烦。其中包含约150个[OperactionContract]。我现在不能再在Visual Studio 2008中更新服务参考。 当我尝试调用更新时,我收到各种奇怪的错误,从“强制关闭套接字”到“无效类型”以及其他奇怪的消息。如果我注释掉10到20个操作,则效果很好。 我在MSDN和许多博客上阅读了各种文章。它们都指向需要在主绑定或MetadataExchange绑定上更改的绑定配置。 我的问题是,我已经尝试了所有这些方法,但尚未使其可靠地工作。 我将服务自托管在一个应用程序中,并且该应用程序也是客户端。它们(当前)共享相同的配置文件,因为我们正在通过Wcf服务层将应用程序分成两部分。 这是摘录,显示了我定义的绑定:<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name=\"NetTcpBinding_IRhinoServices\"
closeTimeout=\"00:05:00\"
openTimeout=\"00:05:00\"
receiveTimeout=\"00:15:00\"
sendTimeout=\"00:05:00\"
transactionFlow=\"false\"
transferMode=\"Buffered\"
transactionProtocol=\"OleTransactions\"
hostNameComparisonMode=\"StrongWildcard\"
listenBacklog=\"100\"
maxBufferPoolSize=\"2147483647\"
maxBufferSize=\"2147483647\"
maxConnections=\"100\"
maxReceivedMessageSize=\"2147483647\">
<readerQuotas maxDepth=\"2147483647\"
maxStringContentLength=\"2147483647\"
maxArrayLength=\"2147483647\"
maxBytesPerRead=\"2147483647\"
maxNaMetableCharCount=\"2147483647\" />
<reliableSession ordered=\"true\"
inactivityTimeout=\"00:10:00\"
enabled=\"false\" />
<security mode=\"None\">
</security>
</binding>
</netTcpBinding>
<customBinding>
<binding name=\"customMex\">
<textMessageEncoding>
<readerQuotas maxDepth=\"2147483647\"
maxStringContentLength=\"2147483647\"
maxArrayLength=\"2147483647\"
maxBytesPerRead=\"2147483647\"
maxNaMetableCharCount=\"2147483647\" />
</textMessageEncoding>
<tcpTransport transferMode=\"Buffered\"
maxReceivedMessageSize=\"2147483647\"
maxBufferSize=\"2147483647\"/>
</binding>
</customBinding>
</bindings>
<client>
<endpoint address=\"net.tcp://localhost:8523/RhinoServices\"
binding=\"netTcpBinding\"
bindingConfiguration=\"NetTcpBinding_IRhinoServices\"
contract=\"RhinoServicesReference.IRhinoServices\"
name=\"NetTcpBinding_IRhinoServices\">
<identity>
<dns value=\"localhost\" />
</identity>
</endpoint>
</client>
<services>
<service behaviorConfiguration=\"CounterSketchServer.RhinoServicesBehavior\"
name=\"CounterSketchServer.RhinoServices\">
<endpoint address=\"\"
binding=\"netTcpBinding\"
contract=\"CounterSketchServer.IRhinoServices\">
<identity>
<dns value=\"localhost\" />
</identity>
</endpoint>
<endpoint address=\"mex\"
binding=\"customBinding\"
contract=\"IMetadataExchange\"
name=\"\"
bindingConfiguration=\"customMex\"
listenUriMode=\"Explicit\" />
<host>
<baseAddresses>
<add baseAddress=\"net.tcp://localhost:8523/RhinoServices\" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name=\"CounterSketchServer.RhinoServicesBehavior\">
<serviceMetadata httpGetEnabled=\"false\" />
<serviceDebug includeExceptionDetailInFaults=\"true\" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
我需要能够通过单击Update Service Reference来生成代理类,该服务在过去的2周中一直有效,直到达到这个神秘的极限。
我看到的大多数示例都可以解决有关mex的http绑定的讨论,但由于我是自托管的,因此我尽可能只使用netTcp。
谁能帮帮我吗?
谢谢。
*更新*
我尝试了@Aliostad建议,起初看起来效果不错。直到我尝试了一些更新UI元素的Wcf调用。当将NetTCP绑定与Visual Studios(添加服务参考)工具生成的代理类一起使用时,这些方法确实起作用。但是当使用Channel Factory时,它不起作用。
我曾尝试查看Juval的WCF书中的SyncrhonizationContext,但似乎没有做任何工作。
我已经尝试使用命名管道和NetTCP作为使用ChannelFactory创建的Channel的绑定,并且它们的行为与长期运行的Wcf操作彼此之间确实有很大不同,但都无法更新UI元素。
我的服务实际上在Rhino 3D CAD引擎的插件中运行,并且ceratin调用(Render等)触发Rhino中的UI进行更新。我认为这会导致线程边界问题。我收到的异常是:
尝试读取或写入受保护的内存
如果有人对在这种情况下有效使用ChannelFactory方法有任何建议,或者对于给定的Wcf类中过多的操作来解决我的问题,以至于无法生成服务代理,我将不胜感激。
谢谢!
解决方法
首先,我相信唯一的解决方案是删除引用,然后再次将其重新添加。
或者,如果您同时拥有“客户端”和“服务”(我似乎是从阅读您的问题中得到的),我是否可以强烈建议您与客户共享服务接口,而不要使用服务引用?
当您同时拥有客户端和服务器时,这绝对是首选方法(这将使您免于遇到的所有麻烦),并且我认为,如果您不拥有客户端,只需共享实体/ dto和接口。
这要求您:
为您的实体/ dto创建一个类库项目。与客户共享。
为您的服务接口创建一个类库项目。与客户共享。
为您的服务实现创建一个类库项目。仅停留在服务器上。
客户端使用
ChannelFactory<T>
创建工厂,然后通过调用CreateChannel()
创建代理。
,我已经从SvcUtil.exe和Visual Studio 2008重新获得了更新服务参考。
为此,我将以下部分添加到了devenv.exe.config和SvcUtil.exe.config的配置文件中:
<!-- CUSTOM MetaDataExchaning Binding to all for LARGE WCF Services -->
<client>
<endpoint name=\"net.tcp\" binding=\"netTcpBinding\" bindingConfiguration=\"GenericBinding\"
contract=\"IMetadataExchange\" />
<endpoint name=\"http\" binding=\"wsHttpBinding\" bindingConfiguration=\"SecureBinding\" contract=\"IMetadataExchange\" />
</client>
<bindings>
<netTcpBinding>
<binding name=\"GenericBinding\" maxBufferPoolSize=\"2147483647\"
maxReceivedMessageSize=\"2147483647\" >
<readerQuotas maxDepth=\"2147483647\" maxStringContentLength=\"2147483647\"
maxArrayLength=\"2147483647\" maxBytesPerRead=\"2147483647\"
maxNameTableCharCount=\"2147483647\" />
<security mode=\"None\"/>
</binding>
</netTcpBinding>
<wsHttpBinding>
<binding name=\"SecureBinding\" maxBufferPoolSize=\"2147483647\"
maxReceivedMessageSize=\"2147483647\" >
<readerQuotas maxDepth=\"2147483647\" maxStringContentLength=\"2147483647\"
maxArrayLength=\"2147483647\" maxBytesPerRead=\"2147483647\"
maxNameTableCharCount=\"2147483647\" />
<security mode=\"Message\">
<transport clientCredentialType=\"Windows\" />
</security>
</binding>
</wsHttpBinding>
</bindings>
然后,在我的应用程序服务器插件中,我仍然以编程方式创建ServiceHost,以便启用元数据交换,我添加了另一个端点:
// DATA ENDPOINT
NetTcpBinding binding = new NetTcpBinding(SecurityMode.Transport,true);
Uri baseAddress = new Uri(\"net.tcp://localhost:8555/RhinoServices\");
_rhinoServicesHost = new ServiceHost(typeof(RhinoServices),baseAddress);
_rhinoServicesHost.AddServiceEndpoint(typeof(IRhinoServices),binding,baseAddress);
// META ENDPOINT
BindingElement bindingElement = new TcpTransportBindingElement();
CustomBinding customBinding = new CustomBinding(bindingElement);
ServiceMetadataBehavior metadataBehavior = _rhinoServicesHost.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (metadataBehavior == null)
{
metadataBehavior = new ServiceMetadataBehavior();
_rhinoServicesHost.Description.Behaviors.Add(metadataBehavior);
}
_rhinoServicesHost.AddServiceEndpoint(typeof(IMetadataExchange),customBinding,\"MEX\");
_rhinoServicesHost.Faulted += RhinoServicesHost_Faulted;
_rhinoServicesHost.Open();
现在,无论合同数量多少,我都可以更新引用。
但我必须承认,在整个过程中,自从我切换回此方法以来,尝试读取或写入受保护的内存错误一直没有消失。
所以我想我还是要追踪一下...
我也在另一个问题(单击查看)上找到了该解决方案,并由@trendl回答。谢谢您的帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。