【发布时间】:2011-12-12 12:20:59
【问题描述】:
根据http://msdn.microsoft.com/en-us/library/bb412178.aspx 上的教程,我目前无法测试应用了WebGet 属性的简单WCF 服务
我创建了一个空白的 ASP.NET Web 应用程序项目,然后添加了一个名为“test”的 WCF 服务,它创建了 test.svc 和 Itest.svc。
然后我添加了方法“你好”:
public class test : Itest
{
public string hello(string s){return "hello " + s;}
}
实现接口:
[ServiceContract]
public interface Itest
{
[OperationContract]
[WebGet]
string hello(string s);
}
但是,对http://localhost/test.svc/hello?s=hi 的任何请求(HTTP GET)都会返回一个空页面。
事实上,该 url 下的任何请求都会返回一个空白页面(即http://localhost/test.svc/abcdefg)
我错过了一些基本的东西吗?
编辑:web.config 完全标准,除了 Visual Studio 生成的:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_Itest" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/test.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_Itest" contract="ServiceReference1.Itest"
name="BasicHttpBinding_Itest" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
【问题讨论】:
-
使用 [WebGet] 属性,我不想将它与服务引用一起使用。话虽如此,它在使用 wcftestclient.exe 进行测试时确实有效
-
我测试了其他浏览器并以编程方式发出了网络请求......仍然得到一个空响应。
-
尝试将
WebGet更新为类似[WebGet(UriTemplate = "foo", BodyStyle = WebMessageBodyStyle.Bare)] -
将 UriTemplate 更改为上述,什么也没做,也没有更改 web.config 的 binding="webHttpBinding"