what is the “behaviorConfiguration” attribute of service?

后端 未结 4 2051
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 05:31

what is the \"behaviorConfiguration\" attribute of service?


      

        
相关标签:
4条回答
  • 2021-02-05 06:00

    You will get this error with Behavior name is not setup correctly.

    The HTML document does not contain Web service discovery information. Metadata contains a reference that cannot be resolved: 'http://blabla.com/WebService/Processor.svc'. Content Type application/soap+xml; charset=utf-8 was not supported by service 'http://blabla.com/WebService/Processor.svc'. The client and service bindings may be mismatched. The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'.. If the service is defined in the current solution, try building the solution and adding the service reference again.

    0 讨论(0)
  • 2021-02-05 06:05

    There are 3 important sections when you configure a WCF service.

    1) Defining the Services:

    <services>
          <service behaviorConfiguration="SOAPRESTDemoBehavior" name="SOAPRESTDemo">
            <endpoint address="rest" behaviorConfiguration="SOAPRESTDemoEndpointBehavior" binding="webHttpBinding" contract="ISOAPRESTDemo" />
            <endpoint address="soap" binding="basicHttpBinding" contract="ISOAPRESTDemo" />
          </service>
        </services>
    

    NOTE the value of behaviorConfiguration is a reference to a section further on in the config see below...

    2) Defining the 'Service Behaviours'

     <serviceBehaviors>
            <behavior name="SOAPRESTDemoBehavior">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
    

    3) Defining the 'Endpoint Behaviours'

    <endpointBehaviors>
            <behavior name="SOAPRESTDemoEndpointBehavior">
              <webHttp/>
            </behavior>
          </endpointBehaviors>
    

    All 3 sections are the basics for what you need to set up a service (although this can be done programatically).

    With regard to your question the behaviorConfiguration section relates to point 2 and 3 in my points above. Its where you lay out the sort of actions you want your service to have. for example above I have said that I want to allow MetaData to be published. This will essentially create a WSDL which describes the service.

    The full config is here:

    <?xml version="1.0"?>
    <configuration>
    
        <system.web>
            <compilation debug="true" targetFramework="4.0" />
        </system.web>
    
      <system.serviceModel>
    
        <!--Set up the service-->
        <services>
          <service behaviorConfiguration="SOAPRESTDemoBehavior" name="SOAPRESTDemo">
            <endpoint address="rest" behaviorConfiguration="SOAPRESTDemoEndpointBehavior" binding="webHttpBinding" contract="ISOAPRESTDemo" />
            <endpoint address="soap" binding="basicHttpBinding" contract="ISOAPRESTDemo" />
          </service>
        </services>
    
    
        <!--Define the behaviours-->
        <behaviors>
    
          <serviceBehaviors>
            <behavior name="SOAPRESTDemoBehavior">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
    
          <endpointBehaviors>
            <behavior name="SOAPRESTDemoEndpointBehavior">
              <webHttp/>
            </behavior>
          </endpointBehaviors>
    
        </behaviors>
    
      </system.serviceModel>
    
    </configuration>
    
    0 讨论(0)
  • 2021-02-05 06:07

    It is a reference to another configuration section:

    <behaviors>
       <serviceBehaviors>
          <behavior name="WcfServiceNetMSMQ.Service1Behavior">
    
          </behaviors>
       </serviceBehaviors>
    </behaviors>
    

    Where this section contains some global configuration for the whole service.

    0 讨论(0)
  • 2021-02-05 06:11

    here's an example of it, it carries some properties of the connection of the service.

    <serviceBehaviors>
    <behavior name="WcfServiceNetMSMQ.Service1Behavior">
     <serviceMetadata httpGetEnabled="true" />
     <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
    

    Notice that the name in this service behavior corresponds to the one you specified earlier.

    Hope that helps.

    0 讨论(0)
提交回复
热议问题