调用Web服务
问题描述:
我试图调用从Outlook插件一个WCF端点增加,但它总是抛出这个错误:调用Web服务
Configuration binding extension 'system.serviceModel/bindings/netHttpsBinding' could not be found. Verify that this binding extension is properly registered in system.serviceModel/extensions/bindingExtensions and that it is spelled correctly.
我app.config文件看起来是这样的:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<system.serviceModel>
<bindings>
<netHttpsBinding>
<binding name="mainBinding" maxReceivedMessageSize="20000000">
<security mode="Transport" />
</binding>
</netHttpsBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="mainBehavior">
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="netHttpBinding" scheme="http" />
<add binding="netHttpsBinding" scheme="https" />
</protocolMapping>
<client>
<endpoint name="MyApp.MyClient" address="https://localhost:44332/Services/MyService.svc" binding="netHttpsBinding" bindingConfiguration="mainBinding" behaviorConfiguration="mainBehavior" contract="MyApp.IMyService">
</endpoint>
</client>
</system.serviceModel>
</configuration>
当我从控制台应用程序(使用相同的App.config)调用服务时,它可以工作。我认为我的参考也是正确的。 有什么问题?
答
请注意,您开发一个加载项,而不是一个独立的应用程序。所有配置均使用主机应用程序配置文件进行。您需要运行下面的代码来获取的app.config工作:
Appdomain.SetData("APP_CONFIG_FILE",@"D:\myapp\app.config");