无法激活请求的服务“http://localhost:10582/Service1.svc?wsdl”

本文主要介绍了在遇到WCF服务无法激活,提示找不到类型的问题时的排查和解决过程。通过检查配置文件和 SVC 文件内容,分别尝试修改终结点地址和 SVC 文件内的服务类型引用,最终成功解决问题。


一、无法激活请求的服务“http://localhost:7221/Service1.svc?wsdl”

接上一篇博客,继续进行测试和调试


        将项目重新生成解决方案后,不再报错误,之后尝试运行UI,看程序是否能正常运行,但是在运行过程中报错了,图示下:


        上面这个IP地址是写在本地服务端UI层的,所以需要先确定服务端是否也存在问题,然后做了下面的操作。

二、找不到类型“WcfService.Service1”,它在 ServiceHost 指令中提供为 Service 特性值,或在配置元素 system.serviceModel/serviceHostingEnvironment/serviceActivations 中提供。


         想要在IIS发布之前,现在浏览器中浏览一遍,看一看服务器是否能正常运行,在svc文件右键,点击在浏览器中浏览,结果:



       出现了错误,会很头疼,但是越焦虑越找不到方法,所以还是理智下来,好好找解决方法吧!

三、解决方法:

      理一理思路,可能是配置文件错误,也可能是WCF创建的 .svc文件错误。之后开始排查应用程序配置文件


app.config 的基本格式:

<configuration>
  <startup>
    <supportedRuntime version ="v4.0" sku =".NETFramework,Version=v4.0"/>
  </startup>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/> 
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
      <!--解决服务器端不能发布成功--><!--
      <serviceActivations >
        <add relativeAddress="Service1.svc" service="WcfService.Service"/>
      </serviceActivations>-->
      
      
    </serviceHostingEnvironment>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_Default" closeTimeout="00:05:00" openTimeout="00:05:00" receiveTimeout="00:20:00" sendTimeout="00:05:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="false" messageEncoding ="Text">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType ="None" realm=""></transport>
            <message clientCredentialType="UserName" algorithmSuite="Default"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    
    <!--终结点ABC-->
    <client>
      <!--<endpoint address="http://localhost:7221/Service.svc?wsdl" binding ="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Default" contract="*" name="BasicHttpBinding_Services"></endpoint>-->
      <endpoint address=" http://localhost:10582/Service1.svc?wsdl" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Default" contract="Contracts.IService" name="BasicHttpBinding_Services"></endpoint>
       <!--<endpoint address="http://localhost:7221/Service.svc?wsdl" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Default" contract="ITOO.Library.Test.Service.Contracts.IService" name="BasicHttpBinding_Services"/>-->
    </client>
    
  </system.serviceModel>
</configuration>

方法1:将终结点endpoint的地址:http://localhost:7221/Service.svc?wsdl 修改为服务器端的地址http://192.168.26.*7221/Service.svc?wsdl

方法2:将svc文件中的内容进行修改如图:

         wcf层目录

          

         wcf 中svc文件代码

<%@ ServiceHost Language="C#" Debug="true" Service="WCFService.Service1" CodeBehind="Service.svc.cs"  %>
        将Service的属性修改为服务名称;

<%@ ServiceHost Language="C#" Debug="true" Service="ITOO.Library.Test.Service.WCFService.Service" CodeBehind="Service.svc.cs"  %>


重新生成项目,浏览服务端,就OK了。


         博客比较水,但是代表了这一天的收获,调试错误永远都会有一个解决方案在等着你,或许是众里寻她,或许是蓦然回首,总之,相信,一定有一个方法在等着你。


<?xml version="1.0" encoding="utf-8"?> <configuration> <system.web> <!-- 编译目标框架 --> <compilation debug="true" targetFramework="4.0" /> <!-- 增加 ASP.NET 请求限制:50MB --> <httpRuntime maxRequestLength="51200" executionTimeout="3600" useFullyQualifiedRedirectUrl="false" /> <pages controlRenderingCompatibilityVersion="4.0" /> <!-- 启用 Web Services 协议 --> <webServices> <protocols> <add name="HttpSoap" /> <add name="HttpPost" /> <add name="HttpGet" /> <add name="Documentation" /> </protocols> </webServices> </system.web> <!-- IIS 设置 --> <system.webServer> <!-- CORS 跨域设置 --> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Methods" value="OPTIONS,POST,GET" /> <add name="Access-Control-Allow-Headers" value="x-requested-with,content-type" /> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> </httpProtocol> <!-- 关键!IIS 层最大请求内容长度(单位:字节)--> <!-- 50MB = 52,428,800 字节 --> <security> <requestFiltering> <requestLimits maxAllowedContentLength="52428800" /> </requestFiltering> </security> <!-- 确保启用运行时环境 --> <modules runAllManagedModulesForAllRequests="true" /> </system.webServer> <!-- 数据库连接字符串 --> <connectionStrings> <add name="_Default" connectionString="data source=ORCL;uid=sst_user;pwd=123;" providerName="System.Data.OracleClient" /> </connectionStrings> <!-- 应用设置 --> <appSettings> <add key="SqlPath" value="d:\" /> <add key="DefaultSqlXmlFileName" value="Sqls" /> <add key="DBWriteLog" value="false" /> <add key="DBLogFill" value="false" /> <add key="DBLogExec" value="false" /> <add key="DBLogUpdate" value="false" /> <add key="CompareAllValuesWhenUpdate" value="false" /> <add key="UnifiedParamPrefix" value="^" /> <add key="BlobFilePath" value="Files\" /> <add key="HisBlobFilePath" value="Backup\" /> </appSettings> <!-- WCF 核心配置 --> <system.serviceModel> <bindings> <basicHttpBinding> <!-- 命名绑定:BasicHttpBinding --> <binding name="BasicHttpBinding" closeTimeout="00:59:59" openTimeout="00:59:59" receiveTimeout="00:59:59" sendTimeout="00:59:59" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="52428800" maxBufferPoolSize="52428800" maxReceivedMessageSize="52428800" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> <!-- 读取器配额必须与消息大小匹配 --> <readerQuotas maxDepth="32" maxStringContentLength="52428800" maxArrayLength="52428800" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <!-- 安全设置:无认证 --> <security mode="None"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding> </basicHttpBinding> </bindings> <behaviors> <serviceBehaviors> <!-- 主要行为 --> <behavior name="WCFServerCABehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> <!-- 提高序列化图限制 --> <dataContractSerializer maxItemsInObjectGraph="2147483647"/> </behavior> <!-- 默认空行为(建议命名) --> <behavior name="EmptyBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> <dataContractSerializer maxItemsInObjectGraph="2147483647"/> </behavior> </serviceBehaviors> </behaviors> <!-- 服务定义 --> <services> <service behaviorConfiguration="WCFServerCABehavior" name="HY.Application.Service.Edf.EdfService"> <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding" contract="HY.Application.API.Edf.IEdfService" /> </service> <service behaviorConfiguration="WCFServerCABehavior" name="HY.Application.Service.Edf.BaseService"> <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding" contract="HY.Application.API.Edf.IBaseService" /> </service> <service behaviorConfiguration="WCFServerCABehavior" name="HY.Application.Service.Edf.CnasService"> <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding" contract="HY.Application.API.Edf.ICnasService" /> </service> <service behaviorConfiguration="WCFServerCABehavior" name="HY.Application.Service.Sst.SstService"> <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding" contract="HY.Application.API.Sst.ISstService" /> </service> </services> </system.serviceModel> </configuration> 提示无法激活服务
最新发布
12-19
评论 5
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值