2010-11-25 55 views
1

我们已经尝试使用HTTp Get获得一个非常非常简单的WCF服务,但我们无法使其工作。 我们跟着那些“指南”,但它不工作如何通过HTTP获取使用WCF服务(在Visual Studio 2010中)

当我们拨打我们的服务与下面的网址,我们得到找不到网页错误:

http://localhost:9999/Service1.svc/GetData/ABC

基本URL(http:// localhost:9999/Service1.svc)工作正常,并正确返回wcf服务信息页面。

这些是重现我们示例的步骤和代码。

  1. 在Visual Studio 2010中,创建一个新的 “WCF服务应用程序” 项目
  2. 与此代码

    [ServiceContract()] 
        public interface IService1 
        { 
         [OperationContract()] 
         [WebInvoke(Method = "GET", 
           BodyStyle = WebMessageBodyStyle.Bare, 
           UriTemplate = "GetData/{value}")] 
         string GetData(string value); 
        } 
    
  3. 更换IService接口与此代码

    public class Service1 : IService1 
    { 
        public string GetData(string value) 
        { 
         return string.Format("You entered: {0}", value); 
        } 
    } 
    
    更换服务类
  4. 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> 
    

  5. 按运行,并试图调用get方法

如果有人得到这或类似的东西的工作,那将是很亲切,如果你能回复有关工作示例的信息。

非常感谢你

回答

1

我重新创建了你的样本 - 作品像一个魅力。

一点:您的服务合同(public interface IService1)和服务实现(public class Service1 : IService1)是否存在于一个.NET命名空间内?

如果是这样,你需要改变你的* .SVC和你web.config包括:

<services> 
     <service name="Namespace.Service1"> 
      <endpoint address="" binding="webHttpBinding" 
        contract="Namespace.IService1" 
        behaviorConfiguration="WebBehavior1"> 
      </endpoint> 
     </service> 
    </services> 

<service name="...">属性和<endpoint contract="...">必须包括这项工作的.NET命名空间。

+0

你是非常正确的...这只是因为缺少根名称空间。它可以正常工作(没有根名称空间)用于其他绑定,但不适用于webHttpBinding。非常感谢你。 – 2010-11-25 17:44:05

相关问题