c# - .NET Web Service receive HTTP POST request (500) Internal Server Error -


i writing c# web service has several methods, 1 of has receive http post requests. first thing have done alter web.config file in web service project below.

<webservices>   <protocols>     <add name="httpsoap"/>     <add name="httppost"/>     <add name="httppostlocalhost"/>     <add name="documentation"/>   </protocols> </webservices> 

i can run web service locally , when click on method in browser, can see handles http post requests , accepts args=string, signature of web method accepts 1 string parameter named args. testing via test asp.net app using code below fire http post request.

httpwebrequest request = (httpwebrequest)httpwebrequest.create(configurationmanager.appsettings["paymenthuburl"].tostring());  request.keepalive = false; request.contenttype = "application/x-www-form-urlencoded"; request.method = "post";  stringbuilder sb = new stringbuilder(); sb.append("message_type="); sb.append(httputility.urlencode("txn_response"));  byte[] bytes = utf8encoding.utf8.getbytes(sb.tostring()); request.contentlength = bytes.length; using (stream poststream = request.getrequeststream()) {     poststream.write(bytes, 0, bytes.length); }  string test; using (httpwebresponse response = (httpwebresponse)request.getresponse()) {      streamreader reader = new streamreader(response.getresponsestream());       test = reader.readtoend(); } 

but when run "the remote server returned error: (500) internal server error". if remove parameter, removing stringbuilder , byte code, having no parameter in web service, works. problem parameters. want send more data, , using string[] parameter in web service, failed.

can help??

i suggest reconsider approach. microsoft has written pretty awesome libraries consuming web services, there 2 ways - "add web reference" , "add service reference".

in case, seems have "asmx web service" recommend add "web reference" project in visual studio. assuming using visual studio.

after add web reference, can create client "new"-ing it. can execute web method on client. easiest way consume web services. not have deal http complications.

hope helps.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -