这里我想使用WCF在我的Restful Web服务中传递Video url作为参数。我在表格中有视频网址列。插入数据时我也想插入视频网址。在Web服务中,我将视频网址作为参数发送。问题在于,传递参数视频网址时包含" \"或" /"。由于这些符号,我无法通过Web服务插入数据。请建议我如何逃避" \"或" /"符号或其他方式将视频网址作为参数传递给宁静的网络服务。
[OperationContract()]
[WebInvoke(UriTemplate = "AddPOI/{POICTG}/{Name}/{Description}/{BestTimetoVisit}/{TimeFrom}/{TimeTo}/{Address}/{Contact_No}/{Lattitude}/{Longitude}/{Altitude}/{Accuracy}/{Image}/{Video_URL}/{Active_Inactive_Flag}", Method = "GET", ResponseFormat = WebMessageFormat.Json)]
bool AddPOI(string POICTG, string Name, string Description, string BestTimetoVisit, string TimeFrom, string TimeTo, string Address, string Contact_No, string Lattitude, string Longitude, string Altitude, string Accuracy, string Image, string Video_URL, string Active_Inactive_Flag);
答案 0 :(得分:0)
服务:
[OperationContract()]
[WebInvoke(UriTemplate = "AddPOI", ResponseFormat = WebMessageFormat.Json)]
bool AddPOI(POIObject objPOIObject);
[DataContract]
public class POIObject
{
[DataMember]
public string POICTG { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Description { get; set; }
[DataMember]
public string BestTimeToVisit{ get; set; }
[DataMember]
public string TimeFrom { get; set; }
[DataMember]
public string TimeTo { get; set; }
[DataMember]
public string Address { get; set; }
[DataMember]
public string Contact_No { get; set; }
[DataMember]
public string Lattitude { get; set; }
[DataMember]
public string Longitude { get; set; }
[DataMember]
public string Altitude { get; set; }
[DataMember]
public string Accuracy { get; set; }
[DataMember]
public string Image { get; set; }
[DataMember]
public string Video_URL { get; set; }
[DataMember]
public string Active_Inactive_Flag { get; set; }
}
现在我来自Fiddler的原始请求如下:
POST http://localhost/XMLService/AddPOI HTTP/1.1
User-Agent: Fiddler
content-type: application/json
Host: localhost:85
Content-Length: 361
{ "POICTG":"1", "Name":"Hello", "Description":"Hi, How are you", "BestTimetoVisit":"Jan", "TimeFrom":"06-12-2015", "TimeTo":"06-13-2015", "Address":"ABC", "Contact_No":"9966555522", "Lattitude":"12.2315332", "Longitude":"12.356465", "Altitude":"2535", "Accuracy":"2365", "Image":"image.png", "Video_URL":"http://www.google.com", "Active_Inactive_Flag":"1" }
回复如下:
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 4
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
Set-Cookie: ASP.NET_SessionId=kz1wx05h4lylpprrxplokl2t; path=/; HttpOnly
X-AspNet-Version: 4.0.30319
Date: Mon, 27 Apr 2015 11:36:12 GMT
true
我已将所有参数包装到一个简单的类对象中,然后执行一个帖子。希望有所帮助