C# WCf REST服务客户端配置文件为空

C# WCf REST服务客户端配置文件为空,c#,wpf,wcf,wcf-rest,C#,Wpf,Wcf,Wcf Rest,我有一个REST服务,并且在我的WPF应用程序中添加了它的引用。但是,一旦我创建了代理的客户端,它就会抛出错误,并且会抛出错误,因为我的客户端app.config为空: <?xml version="1.0" encoding="utf-8" ?> <configuration> </configuration> 这是服务器端web.config的my system.servicemodel部分: <system.serviceModel>

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

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>
这是服务器端web.config的my 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,但运气不好

注意:当我在浏览器中直接浏览时,服务正在工作。因此,服务器端服务没有问题


提前感谢:)

正如其他一些帖子所提到的(如和等),添加服务引用不适用于REST端点。您需要自己创建客户机


web.config中的另一个问题:为了创建REST端点,您需要让webHttpBinding(您执行)向端点添加
端点行为(您不执行)。

创建ServiceReference时,请检查visual studio输出窗口中的警告和错误。即使你在错误列表中没有看到什么,也要检查输出窗口,你看到什么了吗?@Dominik:没有!没什么。你遇到过吗?谢谢你的帮助,但是你能说出“自己创建客户”是什么意思吗。你能给我举个例子吗?或者如果你有,你能展示一下吗?我应该在哪里写。无论我在哪里写,我在web.config中都会看到一条红线,这意味着它无法识别元素。对于“自己创建客户机”:如果您可以在客户机和服务器之间共享相同的[ServiceContract]接口,则可以使用WebChannelFactory(以及采用单个Uri参数的构造函数)创建与服务对话的代理。元素必须位于一个元素内。REST starter kit 2中有可用的HttpClient类。我能用这个吗?
 <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>