WCF rest服务:无法调用方法
请告诉我,我在设置wcf rest服务时做了一些愚蠢的事情。 我已经创建了一个web应用程序,并向其中添加了一个wcf服务 这是我的web.configWCF 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>
<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; }
}