我们已经尝试使用HTTp Get获得一个非常非常简单的WCF服务,但我们无法使其工作。 我们跟着那些“指南”,但它不工作如何通过HTTP获取使用WCF服务(在Visual Studio 2010中)
- http://msdn.microsoft.com/en-us/library/bb412178.aspx
- http://www.dotnetfunda.com/articles/article779-simple-5-steps-to-expose-wcf-services-using-rest-style-.aspx
当我们拨打我们的服务与下面的网址,我们得到找不到网页错误:
基本URL(http:// localhost:9999/Service1.svc)工作正常,并正确返回wcf服务信息页面。
这些是重现我们示例的步骤和代码。
- 在Visual Studio 2010中,创建一个新的 “WCF服务应用程序” 项目
与此代码
[ServiceContract()] public interface IService1 { [OperationContract()] [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetData/{value}")] string GetData(string value); }
更换IService接口与此代码
更换服务类public class Service1 : IService1 { public string GetData(string value) { return string.Format("You entered: {0}", value); } }
web.config看起来像这样
<system.web> <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <services> <service name="Service1"> <endpoint address="" binding="webHttpBinding" contract="IService1" behaviorConfiguration="WebBehavior1"> </endpoint> </service> </services> <behaviors> <endpointBehaviors> <behavior name="WebBehavior1"> <webHttp helpEnabled="True"/> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors>
- 按运行,并试图调用get方法
如果有人得到这或类似的东西的工作,那将是很亲切,如果你能回复有关工作示例的信息。
非常感谢你
你是非常正确的...这只是因为缺少根名称空间。它可以正常工作(没有根名称空间)用于其他绑定,但不适用于webHttpBinding。非常感谢你。 – 2010-11-25 17:44:05