How to consume WCF web service through URL at run time?

后端 未结 5 1168
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 10:06

I want to access all the methods exposed in the service through the URL. if suppose the URL will be :

http://localhost/MyService/MyService.svc
5条回答
  •  时光取名叫无心
    2020-11-30 10:37

    You call it with a /functionname, eg:

    http://localhost/MyService/MyService.svc/GetVersionNumber

    Edit:

    How do you configure your method in the WCF service so you can call it directly from the browser?

    I have an Interface:

    [ServiceContract]
    public interface IWebServiceImpl
    {
        [OperationContract]
        [WebInvoke(Method = "GET",
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "GetVersionNumber")]
        string GetVersionNumber();
    

    And a class to implement the GetVersionNumber method in the Interface:

    public class WebServiceImpl
    {
        public string GetVersionNumber()
        {
                return "1.0.0.0"; //In real life this isn't hard-coded
        }
    }
    

    Finally here is the Web.config configuration:

            
        
          
                
        
          
            
              
            
          
        
        
                      
            
          
        
        
          
            
              
              
              
              
            
          
          
            
              
            
          
        
        
      
      
        
      
    

提交回复
热议问题