我正在创建一个简单的WCF Restful服务。目前,当我浏览到:localhost / AzamSharpService.svc时,它向我展示了Web服务默认页面,我可以在其中检查WSDL。
我想浏览localhost / AzamSharpService.svc / LatestArticles并从GetLatestArticles方法获取json。目前,当浏览到/ LatestArticles网址时,表示找不到页面。
实施如下所示:
[ServiceContract]
public interface IAzamSharpService
{
[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Bare, RequestFormat =WebMessageFormat.Json,ResponseFormat = WebMessageFormat.Json, UriTemplate = "/LatestArticles")]
List<ArticleContract> GetArticles();
}
public class AzamSharpService : IAzamSharpService
{
public List<ArticleContract> GetArticles()
{
var articles = new List<ArticleContract>()
{
new ArticleContract() {Title = "iOS"},
new ArticleContract() { Title="Android"},
new ArticleContract() { Title = "Windows 7"}
};
return articles;
}
}
配置如下所示:
<system.serviceModel>
<services>
<service name="AzamSharpNewLook.AzamSharpService">
<endpoint address="AzamSharpService.svc"
binding="webHttpBinding"
contract="AzamSharpNewLook.IAzamSharpService"
behaviorConfiguration="webby"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webby">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
</system.serviceModel>
答案 0 :(得分:1)
要尝试的几件事......将端点地址设置为空字符串...在webHttp节点中尝试启用帮助...您应该能够导航到localhost / AzamSharpService.svc / help并获取更多信息。最后,我会使用fiddler并在适当的地址构造一个get请求,然后检查响应,你应该得到你需要的东西。希望这会有所帮助...