c# - WCF REST 服务客户端配置文件为空

标签 c# wpf wcf wcf-rest

我有一个 REST 服务,并且已在我的 WPF 应用程序中添加了它的引用。但是,一旦我创建代理的客户端,它就会抛出错误,并且会抛出错误,因为我的客户端 app.config 是空的:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>

客户端上的这一行抛出错误:

 HelloWorldClient client = new HelloWorldClient();

这是服务器端 web.config 的 system.servicemodel 部分:

 <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <services>
      <service name="WCFRestExample.HelloWorld">
        <endpoint address="" binding="webHttpBinding" contract="WCFRestExample.IHelloWorld"/>        
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

谁能告诉我为什么 app.config 是空的?我也重新启动了VS2010,但没有运气。

注意:当我直接在浏览器中浏览它时,该服务正在运行。所以,服务器端服务没有问题。

提前致谢:)

最佳答案

正如其他一些帖子提到的(例如 After creating a wcf service how do I tell whether its restful or soap from the wsdl?Create a WCF Proxy for a Rest Web Service 等),添加服务引用不适用于 REST 端点。您需要自己创建客户端。

web.config 中的另一个问题:为了创建 REST 端点,您需要拥有 webHttpBinding(您所做的)添加 <webHttp/>端点行为到您的端点(您没有)。

关于c# - WCF REST 服务客户端配置文件为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6828060/

相关文章:

sql - WCF 模拟和 SQL 可信连接?

c# - 即时服务器-客户端通信,C#?

字符串崩溃程序中的 C# 特殊字符

c# - 项目使用 Visual Studio 构建良好,但从命令行失败

c# - 动态 CRM - 识别是否已从 PreContactCreate 插件中的潜在客户生成联系人

c# - 声明对象时可以调用类的方法吗?

wpf - 将 WPF ListBox SelectedItem 绑定(bind)到列表

java - 解析 C# 中以 JSON 发送的 DateTime 类型

c# - 为什么 resharper 不建议删除多余的访问修饰符?

c# - DesignInstance 在 VS2013 中不起作用