为客户端控制台应用程序创建代理类以获取消耗WCF服务时出错

时间:2016-06-06 11:21:28

标签: c# asp.net-mvc wcf wcf-binding

我正在研究WFC简单的helloWorld示例,我可以使用WCF测试客户端使用此服务,但是在为客户端应用程序创建代理类以使用此服务时出现错误

C:\My Work\My Development\WCFTestAPP\HelloWorldClient>  http://localhost:63859/HostDevServer/HelloWorldService.svc?wsdl /out:HelloWorldServiceRef.cs /config:app.config
'http:' is not recognized as an internal or external command,
 operable program or batch file.

服务

 [ServiceContract]
interface IHelloWorldService
{
    [OperationContract]
    string GetMessage(string name);
}

服务端实施

public class HelloWorldService : IHelloWorldService
{
    public string GetMessage(string name)
    {
        return "Hello world from " + name + "!";
    }
}

我在项目中添加了asp.net网页,并将其更新为web.config

<configuration>

 <system.web>
  <compilation debug="true" targetFramework="4.5.2" />
  <httpRuntime targetFramework="4.5.2" />
</system.web>
<system.serviceModel>
 <serviceHostingEnvironment >
  <serviceActivations>
    <add factory="System.ServiceModel.Activation.ServiceHostFactory" relativeAddress="~/HostDevServer/HelloWorldService.svc" service="HelloWorldService.HelloWorldService"/>
  </serviceActivations>
</serviceHostingEnvironment>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true"/>
    </behavior>
  </serviceBehaviors>
 </behaviors>
</system.serviceModel>

1 个答案:

答案 0 :(得分:0)

您错过了要运行以生成代理的程序的名称 - svcutil。从开发人员命令提示符处,尝试

svcutil http://localhost:63859/HostDevServer/HelloWorldService.svc?wsdl /out:HelloWorldServiceRef.cs /config:app.config