【发布时间】:2012-02-29 01:07:50
【问题描述】:
请告诉我,我在设置我的 wcf 休息服务时做了一些愚蠢的事情。 我已经创建了一个 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>
还有我的服务接口:
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebGet(UriTemplate = "data/{value}", ResponseFormat = WebMessageFormat.Json)]
Person GetData(string value);
}
还有我的服务代码:
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; }
}
浏览服务没有问题 http://localhost/RoleProviderSite/Service1.svc 但只要我添加数据/10 http://localhost/RoleProviderSite/Service1.svc/data/10 "在 'http://mymachinename/RoleProviderSite/Service1.svc/data/10" 处没有积极监听的频道
我原以为添加“[WebGet(UriTemplate = "data/{value}", ResponseFormat = WebMessageFormat.Json)]" 意味着可以访问此 url,但也许我遗漏了什么?
我正在使用: 互联网信息服务,版本:5.1 和 XP 操作系统
非常感谢您的帮助。
【问题讨论】: