WCF cannot create custom endpointbehavior only in PROD environment

拥有回忆 提交于 2019-12-12 03:23:11

问题


I have a WCF rest web service. Everything works fine on my development environment (#develop using IIS express), but i get the following error on my production evironment:

Server Error in '/Services' Application. --------------------------------------------------------------------------------

Configuration Error 
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

Parser Error Message: An error occurred creating the configuration section handler for system.serviceModel/behaviors: Extension element 'inspectMessageBehavior' cannot be added to this element.  Verify that the extension is registered in the extension collection at system.serviceModel/extensions/behaviorExtensions.
Parameter name: element

Source Error: 


Line 16:            </service>
Line 17:        </services>
Line 18:        <behaviors>
Line 19:            <endpointBehaviors>
Line 20:                <behavior name="webHttp">


Source File: C:\Otimis\AdvLinkForWebService\services\web.config    Line: 18 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053 

This is my web.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <services>
            <service name="AdvLinkForWebService.inbound">
                <endpoint address=""
                          binding="webHttpBinding"
                          contract="AdvLinkForWebService.Iinbound"
                          behaviorConfiguration="defaultWebHttpBehavior"/>
            </service>
            <service name="AdvLinkForWebService.config">
                <endpoint address=""
                          binding="webHttpBinding"
                          contract="AdvLinkForWebService.Iconfig"
                          behaviorConfiguration="webHttp"/>
            </service>
        </services>
        <behaviors>
            <endpointBehaviors>
                <behavior name="webHttp">
                    <webHttp/>
                </behavior>
                <behavior name="defaultWebHttpBehavior">
                    <inspectMessageBehavior/>
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <extensions>
            <behaviorExtensions>
                <add name="inspectMessageBehavior"
                     type="AdvLinkForWebService.MessageInspector.InspectMessageBehaviorExtension, AdvLinkForWebService"/>
            </behaviorExtensions>
        </extensions>
    </system.serviceModel>
</configuration>

This question is related to this one


回答1:


To run properly in my production evironment, it was necessary to specify the version, culture and key for inspectMessageBehavior. Ended up with the following configuration file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <extensions>
            <behaviorExtensions>
                <add name="inspectMessageBehavior"
                     type="AdvLinkForWebService.MessageInspector.InspectMessageBehaviorExtension, AdvLinkForWebService, Version=1.0.5791.17758, Culture=neutral, PublicKeyToken=null"/>
            </behaviorExtensions>
        </extensions>
        <behaviors>
            <endpointBehaviors>
                <behavior name="defaultWebHttpBehavior">
                    <webHttp/>
                    <inspectMessageBehavior/>
                </behavior>
                <behavior name="webHttp">
                    <webHttp/>
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <services>
            <service name="AdvLinkForWebService.inbound">
                <endpoint address=""
                          binding="webHttpBinding"
                          contract="AdvLinkForWebService.Iinbound"
                          behaviorConfiguration="defaultWebHttpBehavior"/>
            </service>
            <service name="AdvLinkForWebService.config">
                <endpoint address=""
                          binding="webHttpBinding"
                          contract="AdvLinkForWebService.Iconfig"
                          behaviorConfiguration="webHttp"/>
            </service>
        </services>
    </system.serviceModel>
</configuration>

I don't know exactly how the version number is generated, even if it can be controlled, but I obtained it with the following command:

typeof(InspectMessageBehaviorExtension).AssemblyQualifiedName


来源:https://stackoverflow.com/questions/33545824/wcf-cannot-create-custom-endpointbehavior-only-in-prod-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!