简体   繁体   English

在C#中使用WCF在Web服务中将Web URL作为参数传递

[英]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. 在这里,我想使用WCF在我的Restful Web服务中将视频URL作为参数传递。 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. 由于这些符号,我无法通过Web服务插入数据。 Please suggest me how to escape "\\" or "/" symbols or other way to pass video url as parameter in restful web service. 请建议我如何在静态Web服务中转义“ \\”或“ /”符号或以其他方式将视频url作为参数传递。

[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: 现在,我对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" } 

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 希望能有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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