Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WCF rest服务:无法调用方法_Wcf_Json_Rest - Fatal编程技术网

WCF rest服务:无法调用方法

WCF rest服务:无法调用方法,wcf,json,rest,Wcf,Json,Rest,请告诉我,我在设置wcf rest服务时做了一些愚蠢的事情。 我已经创建了一个web应用程序,并向其中添加了一个wcf服务 这是我的web.config <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel>

请告诉我,我在设置wcf rest服务时做了一些愚蠢的事情。 我已经创建了一个web应用程序,并向其中添加了一个wcf服务

这是我的web.config

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>

    <system.serviceModel>
      <services>
        <service name="WebApplication1.Service1">
          <endpoint address="../Service1" behaviorConfiguration="httpBehavior"

                binding="webHttpBinding"
                contract="WebApplication1.IService1"/>
        </service>
      </services>
      <behaviors>
        <endpointBehaviors>
          <behavior name="httpBehavior">
            <webHttp helpEnabled="true" />
          </behavior>
        </endpointBehaviors>
        <serviceBehaviors>
            <behavior name="">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <startup>
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
</configuration>
和我的服务代码:

public class Service1 : IService1
    {

        public Person GetData(string value)
        {
            return new Person()
            {
                Id = Convert.ToInt32(value),
                Name = "John Doe"
            };
        }
    }

    public class Person
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
我在浏览服务时没有问题 但只要我添加数据/10 “没有频道积极收听”http://mymachinename/RoleProviderSite/Service1.svc/data/10"

我本以为添加“[WebGet(UriTemplate=“data/{value}”,ResponseFormat=WebMessageFormat.Json)]意味着可以访问这个url,但也许我遗漏了什么

我正在使用: 互联网信息服务,版本:5.1 和XP操作系统


非常感谢您的帮助。

删除终结点中的地址,您的URI将按预期工作。您不能像端点那样使用相对寻址

请删除端点中的地址,您的URI应按预期工作。不能对端点使用这样的相对寻址

public class Service1 : IService1
    {

        public Person GetData(string value)
        {
            return new Person()
            {
                Id = Convert.ToInt32(value),
                Name = "John Doe"
            };
        }
    }

    public class Person
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }