我是 WCF 的新手,正在尝试制作我的第一个服务(一个简单的使用情况报告服务)。我浏览了示例和教程并创建了一个服务。我有一个简单的测试程序,可以运行我的核心代码并发送报告。目前我在调试器中本地运行,但是运行这个简单的 exe 程序托管服务,发送报告,服务创建日志文件,就像它应该做的那样......一切都很好。
现在,我的实际程序是另一个在其 API (Autodesk Revit) 中运行的商业程序的插件。当我在 Revit API 中运行完全相同的代码时,我收到一个错误,即没有定义端点。我的猜测是这是因为它正在寻找主要的 Revit.exe.config 显然不会定义我的端点。我为我的 dll 创建了一个 .config 文件(MyLibrary.dll.config),并在我的代码的执行目录中,它正确定义了端点,但似乎无法识别。
所以我的问题是如何让它从这个配置文件中加载连接设置?还是我应该这样做的另一种方式?我愿意以某种方式或其他方式在代码中设置它,只是无法弄清楚如何让它连接......
我不确定这是否重要,但这是在独立程序中运行的配置:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IReportingService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8733/Design_Time_Addresses/SPECtrumReportingService/Service1/"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IReportingService"
contract="ReportService.IReportingService" name="BasicHttpBinding_IReportingService" />
</client>
</system.serviceModel>
</configuration>
我抛出端点异常的构造函数很简单:
_reporter = new ReportingServiceClient();
这是引发的异常:
Could not find default endpoint element that references contract 'ReportService.IReportingService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
at System.ServiceModel.ConfigurationEndpointTrait`1.CreateSimplexFactory()
at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
at RDES.Revit.Sumex.CommonUse.ReportService.ReportingServiceClient..ctor() in c:\RD\Projects\13-004 SPECtrum\Code\SPECtrumBase\Service References\ReportService\Reference.cs:line 241
at RDES.Revit.Sumex.CommonUse.ImportVM..ctor() in c:\RD\Projects\13-004 SPECtrum\Code\SPECtrumBase\ImportVM.cs:line 41
任何帮助将不胜感激...