添加服务引用不适用于没有SVC文件的WCF服务

时间:2013-11-21 08:02:07

标签: .net wcf

我有一个没有* .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>

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

1 个答案:

答案 0 :(得分:0)

如果您创建WCF-Service,则必须创建一个主机应用程序,您无法自行启动此WCF-Library

如果要从Host-Application启动WCF服务,请创建WCF-Application。在那里你有一个svc,你可以按照你在问题中描述的那样开始它。