简体   繁体   中英

passing web url as parameter in web service using wcf in c#

当我从Angularjs发送对象时,我得到的是“ GET”动词而不是“ POST”这是我得到的错误提交数据后 Here I want to pass Video url as parameter in my Restful web service using WCF. I have Video url Column in a table. While inserting data I want to insert video url too. In web service I am sending the video url as parameter. The problem is that, While passing parameter video url consist of "\\" or "/". Because of these symbols I am not able to insert data through web service. Please suggest me how to escape "\\" or "/" symbols or other way to pass video url as parameter in restful web service.

[OperationContract()] 
[WebInvoke(UriTemplate = "AddPOI/{POICTG}/{Name}/{Description}/{BestTimetoVisit}/{TimeFrom}/{TimeTo}/{Add‌​ress}/{Contact_No}/{Lattitude}/{Longitude}/{Altitude}/{Accuracy}/{Image}/{Video_U‌​RL}/{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);

Service :

[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; }

}

Now my raw request from Fiddler looks as below:

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" } 

The response is below:

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

I have wrapped all the parameters into a simple class object and then performing a post. Hope that helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM