using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebService2
{
/// <summary>//bd
/// Summary description for Service1
/// </summary>bd
[WebService(Namespace = "http://192.168.0.213/WebService/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string add(int param1, int param2)
{
try
{
int sum = param1 + param2;
return sum.ToString();
}
catch { return "Value is wrong"; }
}
}
}
ครับ
ของ android
package com.example.add;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
//BD
public class FeedDataWebService2s extends Activity implements OnClickListener {
private static String SOAP_ACTION = "http://192.168.0.213/WebService/add";
private static String NAMESPACE = "http://192.168.0.213/WebService/";
private static String METHOD_NAME = "add";
private static String URL = "http://192.168.0.213/WebService/service.asmx?WSDL";
Button btnAns;
EditText edt_Param1,edt_Param2,edt_Ans;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activitymain);
btnAns = (Button)findViewById(R.id.btn_Ans);
edt_Param1 = (EditText)findViewById(R.id.edit_Param1);
edt_Param2 = (EditText)findViewById(R.id.edit_Param2);
edt_Ans = (EditText)findViewById(R.id.edit_Ans);
btnAns.setOnClickListener(this); // Link Event Button
}
public void onClick(View arg0) {
//Initialize soap request + add parameters
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
String param1 = edt_Param1.getText().toString();
String param2 = edt_Param2.getText().toString();
//
//Use this to add parameters
request.addProperty("param1",Integer.valueOf(param1));
request.addProperty("param2",Integer.valueOf(param2));
//Declare the version of the SOAP request
SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION , envelope);
} catch (Exception e) {
e.printStackTrace();
}
SoapObject result = (SoapObject)envelope.bodyIn;
if(result != null){
edt_Ans.setText(result.getProperty(0).toString());
}
}
}
มันerror ตรง
Code
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);