应用程序中的server错误,没有名称为“ServiceBehavior”的服务行为

时间:2023-03-09 19:27:08
应用程序中的server错误,没有名称为“ServiceBehavior”的服务行为

应用程序中的server错误,没有名称为“ServiceBehavior”的服务行为

        今天在阅读“创建和使用Web服务”的相关内容,在浏览器中查看Service.svc文件时遇到错误:应用程序中的server错误,没有名称为“ServiceBehavior”的服务行为。
应用程序中的server错误,没有名称为“ServiceBehavior”的服务行为
        查看源码:
<?

xml version="1.0"?

>
<configuration>
<connectionStrings>
<add name="NorthwindConnectionString" connectionString="Data Source=.;Initial Catalog=Northwind;User ID=sa;Password=123" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies></compilation>
</system.web>
<system.serviceModel>
<services>
<service name="ProductsService" behaviorConfiguration="ServiceBehavior">
<!--Service Endpoints-->
<endpoint address="" binding="wsHttpBinding" contract="IProductsService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- 为避免泄漏元数据信息,请在部署前将下面值设置为 false 并删除上面的元数据终结点 -->
<serviceMetadata httpGetEnabled="true"/>
<!-- 要接收故障异常具体信息以进行调试。请将下面值设置为 true。在部署前设置为 false 以避免泄漏异常信息-->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>

细致研读代码。原来须要在<behavior>节点加入属性:name="ServiceBehavior"。改动完毕后。在浏览器中查看。得到正确的Web服务。

应用程序中的server错误,没有名称为“ServiceBehavior”的服务行为