从 Outlook 添加调用 Web 服务

Calling web service from outlook add in

我正在尝试从 outlook 插件调用 WCF 端点,但它总是抛出此错误:

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");

有关详细信息,请参阅 Problem with excel add-in and app.config