Invoking WCF service method through a browser

前端 未结 3 1285
一生所求
一生所求 2020-12-01 05:40

I\'ve a WCF service which uses basic http binding. How do I invoke its operations/methods through a browser?

3条回答
  •  遥遥无期
    2020-12-01 06:03

    You would need to add WebGetAttribute to your method like following sample

    [OperationContract]
    [WebGet(UriTemplate = "/placesList/{userId}",
    ResponseFormat = WebMessageFormat.Xml)]
    List GetAllPlacesForUser(String userId)
    {
      string xml = "";
      // build xml here
      return xml;
    }
    

    Now in the browser, you could invoke the method like this

    http://localhost:8085/GeoPlacesDataService/placesList/10
    where 10 is the userId parameter.

    Note: In order to add WebGetAttribute you have to reference System.ServiceModel.Web namespace which is found in a separate assembly

提交回复
热议问题