开发者

WCF Service Call during post

开发者 https://www.devze.com 2023-02-23 14:10 出处:网络
I have given [WebGet(UriTemplate = \"/{year}/{issue}/{article}\")] Article GetArticle(string year, string issue, string article);

I have given

[WebGet(UriTemplate = "/{year}/{issue}/{article}")] 

Article GetArticle(string year, string issue, string article); 

[OperationContract] 

[WebInvoke(UriTemplate = "/{year}/{issue}",Method="POST")] 

Article AddArticle(string year, string issue, Article article);

My URL is http://localhost:1355/Issues.svc/

if I give this I am fetching all data from the database

http://localhost:1355/Issues.svc/2010/June/A

GetArticle method fires for the filtered data to bring from db.

Simila开发者_Python百科rly I have to call the Add Article(WebInvoke) method to insert data in to the database. How should I call this method in the browser

how my url should be should I give method=post


check this post help you to achieve the task you want :Create REST service with WCF and Consume using jQuery


You won't be able to send an HTTP post from a browser by just modifying the URL. You'll have to have a web page with a HTML form, some Javascript code, some server-side code, or something else that has the ability to make an HTTP POST request to your service URL.

If you are just wanting to test your service while in development, here's a good HTTP debugging tool that you might want to check out: http://fiddler2.com


You can't use post it using browser url.

Try this code

//Creating the Web Request.
HttpWebRequest httpWebRequest = HttpWebRequest.Create("http://localhost/DemoApp/Default.aspx") as HttpWebRequest;
//Specifing the Method
httpWebRequest.Method = "POST";
//Data to Post to the Page, itis key value pairs; separated by "&"
string data = "Username=username&password=password";
//Setting the content type, it is required, otherwise it will not work.
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
//Getting the request stream and writing the post data
using (StreamWriter sw = new StreamWriter(httpWebRequest.GetRequestStream()))
{
    sw.Write(data);
}
//Getting the Respose and reading the result.
HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
using (StreamReader sr = new StreamReader(httpWebResponse.GetResponseStream()))
{
    MessageBox.Show(sr.ReadToEnd());
}

Source : http://www.dotnetthoughts.net/2009/11/10/post-data-using-httpwebrequest-in-c-sharp/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号