我有一个 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/