0

我正在创建一个简单的 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>
4

1 回答 1

1

有几件事要尝试...将端点地址设置为空字符串...在 webHttp 节点中尝试启用帮助...您应该能够导航到 localhost/AzamSharpService.svc/help 并获取更多信息。最后,我会使用 fiddler 并构造一个到适当地址的 get 请求,然后只需检查响应,你应该有你需要的东西。希望这可以帮助...

于 2012-07-16T21:27:43.970 回答