无法激活请求的服务“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
<think>我们正在使用wsdl2h工具生成ONVIF服务的头文件,命令中列出了多个WSDL文件的URL。现在需要将其中一个URL(ver20/analytics/wsdl/analytics.wsdl)替换为本地文件路径。 原命令: wsdl2h -c -o onvif.h -t ./typemap.dat [多个WSDL的URL] ver20//analytics//wsdl//analytics.wsdl [其他URL] 要求:将`ver20//analytics//wsdl//analytics.wsdl`替换为本地文件路径,比如`/path/to/local/analytics.wsdl` 注意:原命令中该WSDL使用的是相对路径(且使用了双斜杠),但实际在命令行中指定本地文件时,应该使用正确的本地路径。 修改后的命令示例: wsdl2h -c -o onvif.h -t ./typemap.dat http://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl ... 其他URL ... /absolute/path/to/analytics.wsdl ... 其他URL 但是要注意,原命令中该WSDL的位置是在其他URL中间,所以替换时要注意顺序和位置。 具体步骤: 1. 确定要替换的WSDL在命令列表中的位置:在给出的命令中,`ver20//analytics//wsdl//analytics.wsdl`是作为其中一个参数出现的。 2. 由于这个路径是相对路径,而且可能因为网络问题无法访问(之前错误可能是由于该原因),所以我们替换为本地已经下载好的文件路径(绝对路径或相对路径,建议使用绝对路径避免歧义)。 3. 在命令中,直接将该参数替换为本地文件路径即可。 修改后的命令如下(假设本地文件路径为`/home/user/onvif/wsdl/analytics.wsdl`): wsdl2h -c -o onvif.h -t ./typemap.dat \ http://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl \ http://www.onvif.org/ver10/media/wsdl/media.wsdl \ https://www.onvif.org/ver10/recording.wsdl \ http://www.onvif.org/ver10/replay.wsdl \ https://www.onvif.org/ver10/search.wsdl \ http://www.onvif.org/ver10/events/wsdl/event.wsdl \ /home/user/onvif/wsdl/analytics.wsdl \ # 这里替换为本地路径 http://www.onvif.org/ver20/ptz/wsdl/ptz.wsdl \ http://www.onvif.org/ver20/media/wsdl/media.wsdl \ http://www.onvif.org/ver10/deviceio.wsdl \ https://www.onvif.org/ver10/display.wsdl \ https://www.onvif.org/ver10/receiver.wsdl 注意:替换时要确保路径正确,并且该本地文件确实存在,否则会报错。 另外,如果原命令中的`ver20//analytics//wsdl//analytics.wsdl`是相对于某个基础URL的,但现在我们使用本地文件,所以不再需要网络访问。同时,如果其他WSDL文件也有网络访问问题,也可以考虑全部下载到本地,然后全部使用本地路径。 但是,根据问题,我们只替换指定的analytics.wsdl。 因此,答案是:可以,只需将原命令中的`ver20//analytics//wsdl//analytics.wsdl`替换为本地文件路径即可。 </think>是的,完全可以在 `wsdl2h` 命令中将 `analytics.wsdl` 替换为本地文件路径。以下是修改后的命令及注意事项: ### 修改后的命令 ```bash wsdl2h -c -o onvif.h -t ./typemap.dat \ http://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl \ http://www.onvif.org/ver10/media/wsdl/media.wsdl \ https://www.onvif.org/ver10/recording.wsdl \ http://www.onvif.org/ver10/replay.wsdl \ https://www.onvif.org/ver10/search.wsdl \ http://www.onvif.org/ver10/events/wsdl/event.wsdl \ file:///path/to/local/analytics.wsdl \ # 替换为本地文件路径 http://www.onvif.org/ver20/ptz/wsdl/ptz.wsdl \ http://www.onvif.org/ver20/media/wsdl/media.wsdl \ http://www.onvif.org/ver10/deviceio.wsdl \ https://www.onvif.org/ver10/display.wsdl \ https://www.onvif.org/ver10/receiver.wsdl ``` ### 关键修改说明 1. **路径格式** 使用 `file://` 协议前缀指向本地文件(如 `file:///home/user/wsdl/analytics.wsdl`) - Windows 示例:`file://C:/path/to/analytics.wsdl` - Linux/macOS 示例:`file:///home/user/wsdl/analytics.wsdl` 2. **路径要求** - 使用**绝对路径**确保可靠性(建议) - 文件需具有可读权限:`chmod a+r /path/to/analytics.wsdl` - 避免特殊字符:路径中不要包含空格或 `&` 等符号 3. **验证本地文件** 执行前检查文件有效性: ```bash # 检查文件是否存在 ls -l /path/to/local/analytics.wsdl # 验证是否为合法 WSDL head -n 5 /path/to/local/analytics.wsdl # 应显示 XML 声明 ``` ### 替代方案(推荐) 若频繁使用本地文件,建议将所有 WSDL 下载到本地目录: ```bash # 创建本地仓库 mkdir -p onvif_wsdls/ver20/analytics/wsdl cp /path/to/analytics.wsdl onvif_wsdls/ver20/analytics/wsdl/ # 使用本地路径运行 wsdl2h -c -o onvif.h -t ./typemap.dat \ ./onvif_wsdls/ver10/device/wsdl/devicemgmt.wsdl \ ./onvif_wsdls/ver10/media/wsdl/media.wsdl \ ... \ ./onvif_wsdls/ver20/analytics/wsdl/analytics.wsdl \ ... ``` > **优势**:避免网络依赖,提高生成速度,确保构建稳定性
评论 5
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值