我有一个使用基本 http 绑定(bind)的 WCF 服务。 如何通过浏览器调用其操作/方法?
最佳答案
您需要将 WebGetAttribute 添加到您的方法中,如下例所示
[OperationContract]
[WebGet(UriTemplate = "/placesList/{userId}",
ResponseFormat = WebMessageFormat.Xml)]
List<Places> GetAllPlacesForUser(String userId)
{
string xml = "";
// build xml here
return xml;
}
现在在浏览器中,您可以像这样调用该方法
http://localhost:8085/GeoPlacesDataService/placesList/10
where 10 is the userId parameter.
注意:为了添加 WebGetAttribute,您必须引用位于单独程序集中的 System.ServiceModel.Web 命名空间
关于wcf - 通过浏览器调用WCF服务方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/802518/