Using csharp Syntax Highlighting
- //-----------------------------------------//
- using System;
- using System.Web;
- using System.Web.Services;
- using System.Web.Services.Protocols;
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- public class Service : System.Web.Services.WebService
- {
- public Service () {
- }
- [WebMethod]
- public int Add(int a, int b){
- return a + b;
- }
- }
- //-----------------------//
- And here is Client written by Android:
- //-----------------//
- public class WebserviceAdd extends Activity implements OnClickListener{
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- setContentView(R.layout.main);
- Button login=(Button)findViewById(R.id.btntinh);
- login.setOnClickListener(this);
- }
- public void onClick(View arg0) {
- EditText value_a = (EditText)findViewById(R.id.txt_value_a);
- EditText value_b = (EditText)findViewById(R.id.txt_value_b);
- String a = value_a.getText().toString().trim();
- String b = value_b.getText().toString().trim();
- HttpClient client = new HttpClient();
- PostMethod get = new PostMethod("http://127.0.0.1:1496/WebService_Add_Sub_Mul_Div/ Service.asmx?op=Add");
- get.addRequestHeader("a", a);
- get.addRequestHeader("b", b);
- try {
- int status = client.executeMethod(get);
- EditText result = (EditText)findViewById(R.id.txtResult);
- String res = "";
- if(status!=404){
- res=get.getResponseBodyAsString();
- }
- else
- res="Error";
- result.setText(res);
- }
- catch(Exception ex){
- showAlert("Error", ex.toString(), "ok", true);
- }
- finally {
- get.releaseConnection();
- get = null;
- }
- }
- }
- //-------------------------//
Parsed in 0.018 seconds, using GeSHi 1.0.8.4
When i run Server(C#, WebService) and Client (Android), it show a alert "Java.IO.IOException: Connection refused". I don't know why. Please help me. Thanks






