【问题标题】:Add Service Reference not working for WCF service without SVC file添加服务参考不适用于没有 SVC 文件的 WCF 服务
【发布时间】:2013-12-05 14:18:00
【问题描述】:

我有一个没有 *.SVC 文件的现有 WCF 服务。项目本身就是网站,WCF 代码就写在里面。它正在使用此行来注册服务:

RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHostFactory(), typeof(Service1)));

我从 Visual Studio 运行该项目,并通过测试以下方法从 IE 中检查该服务是否已托管和工作:

http://localhost:51838/GetBenchMark/20

我必须创建一个使用此 WCF 服务的控制台应用程序。当我尝试使用 Visual Studio 中的“添加服务参考”并给出路径 http://localhost:51838/ 时,它无法找到它并给出错误:

    The HTML document does not contain Web service discovery information.
Metadata contains a reference that cannot be resolved: 'http://localhost:51838/'.
There was no endpoint listening at http://localhost:51838/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The remote server returned an error: (404) Not Found.
If the service is defined in the current solution, try building the solution and adding the service reference again.

如果有帮助,这是 web.config:

 <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
  </system.web>
  <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="2147483647" />
      </webServices>
    </scripting>
  </system.web.extensions>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </modules>
  </system.webServer>
  <system.serviceModel>
    <client />
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <standardEndpoints>
      <webHttpEndpoint>
        <!-- 
            Configure the WCF REST service base address via the global.asax.cs file and the default endpoint
            via the attributes on the <standardEndpoint> element below
        -->
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" />
      </webHttpEndpoint>
    </standardEndpoints>
    <bindings>
      <webHttpBinding>
        <binding closeTimeout="00:20:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" transferMode="Buffered" useDefaultWebProxy="true">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </webHttpBinding>
    </bindings>
  </system.serviceModel>

请告诉我应该如何生成代理类并从控制台应用程序开始使用此服务。

【问题讨论】:

标签: .net wcf


【解决方案1】:

如果你创建一个WCF-Service,你必须创建一个Host-Application,你不能自己启动这个WCF-Library

如果您想独立于主机应用程序启动 WCF 服务,请创建一个WCF-Application。你有一个svc,你可以像你在问题中描述的那样开始它。

【讨论】:

  • 项目为网站项目,WCF代码写在项目内。因此,我可以从 Visual Studio 运行/调试它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-04-03
  • 1970-01-01
  • 2013-12-21
  • 2015-04-09
  • 1970-01-01
  • 1970-01-01
  • 2015-12-14
相关资源
最近更新 更多