2017-06-10 12 views
0

JSON形式を返すWCF RESTサービスを作成しました。 私の質問は「私の操作契約方法はブラウザで見つけることができませんか?以下はブラウザでWCF RESTサービスメソッドを呼び出す方法

enter image description here

using System.ServiceModel; 
using System.ServiceModel.Web; 
using System.Text; 

namespace WcfService1 
{ 

    public class Service1 : IService1 
    { 
     [WebInvoke(Method = "GET", 
        ResponseFormat = WebMessageFormat.Json, 
        UriTemplate = "data/{id}")] 
     public Person GetData(string id) 
     { 
      // lookup person with the requested id 
      return new Person() 
      { 
       Id = Convert.ToInt32(id), 
       Name = "Leo Messi" 
      }; 
     } 


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

Service1.svc.cs私のサービス契約

using System.ServiceModel; 
using System.ServiceModel.Web; 
namespace WcfService1 
{ 

    [ServiceContract] 
    public interface IService1 
    { 

      [OperationContract] 
      WcfService1.Service1.Person GetData(string id); 

    } 


} 

ある下回っていた私はFsactoryの下に追加することで解決したエンドポイント

<system.serviceModel> 
    <services> 
     <service name="WcfService1.Service1"> 
     <endpoint address="http://localhost:62030/Service1.svc" binding="webHttpBinding" contract="WcfService1.IService1"/> 
     </service> 
    </services> 
    <client> 
     <endpoint name="JsonService1" address="http://localhost:62030/Service1.svc" binding="webHttpBinding" contract="WcfService1.IService1"></endpoint> 
    </client> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, set the values below to false before deployment --> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <protocolMapping> 
     <add binding="webHttpBinding" scheme="https" /> 
    </protocolMapping>  
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" /> 
    </system.serviceModel> 

答えて

0

service1.cs

Factory="System.ServiceModel.Activation.WebServiceHostFactory" 

Service1.cs

<%@ ServiceHost Language="C#" Debug="true" Service="WcfService1.Service1" CodeBehind="Service1.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %> 

JSON出力:enter image description here

関連する問題