在Com可视程序集中使用WCF服务
我必须使用COM可见程序集使用Windows服务中托管的WCF服务 我有一个托管在Windows服务中的WCF服务,我必须在COM可见程序集中使用该服务,我创建了一个COM+应用程序并向其添加了一个服务引用。下面是在Com可视程序集中使用WCF服务,wcf,asp-classic,com+,Wcf,Asp Classic,Com+,我必须使用COM可见程序集使用Windows服务中托管的WCF服务 我有一个托管在Windows服务中的WCF服务,我必须在COM可见程序集中使用该服务,我创建了一个COM+应用程序并向其添加了一个服务引用。下面是app.config <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <bindings>
app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="TcpEndpoint" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://serverMachine:9600/DocumentsWcfService/Tcp"
binding="netTcpBinding" bindingConfiguration="TcpEndpoint"
contract="MysWcfService.IMysWcfService" name="TcpEndpoint" />
</client>
</system.serviceModel>
</configuration>
当我在一个经典的ASP项目中使用这个程序集并调用初始化服务的方法时,我得到的错误如下。但当我在控制台应用程序中引用相同的WCF服务时,它工作得很好。是否需要在COM可视应用程序中进行任何特定更改
在ServiceModel客户端配置节中找不到引用约定“MyWcfService.IMysWcfService”的默认终结点元素。这可能是因为找不到应用程序的配置文件,或者在客户端元素中找不到与此约定匹配的端点元素
COM服务器不读取普通配置文件,因此您需要通过代码或使用以下技巧来执行此操作: (您的COM服务器必须是
.exe
)
Application.manifest
的文件。该文件必须包含:
Application.config
,而不是“myapp.exe.config”现在,配置文件的工作方式与控制台应用程序相同 尝试使用读取配置
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = "MysWcfService.dll.config";
configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
然后,您可以尝试阅读一些wcf配置部分,并以编程方式配置主机():
如果这是com组件正在调用的DLL,您将无法依赖应用程序配置,但必须通过代码进行配置。@PatFromCanada我正在将WCF服务引用直接添加到com组件并在ASP中使用com组件。如果必须通过代码进行配置,如果没有硬编码地址,我们如何使用端点,请您指向任何资源谢谢。Adrian的答案是一种方法,当然您可以创建一个文本(XML)文件并将地址放在其中,我从未处理过这个特定问题。谢谢@Adrian,但对于我的应用程序,我们不能将COM服务器作为exe,因为我们需要在ASP应用程序中使用该COM对象。我没有创建.exe,但在生成后事件命令行下为COM项目添加了“C:\Windows\Microsoft.NET\Framework\v4.0.30319\regsvcs/appdir:$(ProjectDir)$(TargetFileName)”其中ProjectDir是包含Application.config和Application的位置。manifest@ARV,它是否也与.dll一起工作?(我自己从未尝试过,但我只是假设它不起作用,因为dll:s不加载配置文件)。为什么不能使用.exe作为ASP的COM服务器?
ServicesSection servicesSection = (ServicesSection)configuration.GetSection("system.serviceModel/services");
ServiceEndpointElement endpoint = servicesSection.Services[0].Endpoints[0];
//use endpoint.Address
//use endpoint.Binding
//use endpoint.Contract