2015-04-23 279 views
1

我試圖調用從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)調用服務時,它可以工作。我認爲我的參考也是正確的。 有什麼問題?

回答

0

請注意,您開發一個加載項,而不是一個獨立的應用程序。所有配置均使用主機應用程序配置文件進行。您需要運行下面的代碼來獲取的app.config工作:

Appdomain.SetData("APP_CONFIG_FILE",@"D:\myapp\app.config"); 

更多信息請參見Problem with excel add-in and app.config