Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
package com.example.dotnwebservice;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;

public class WebserviceCall {
	
	//String namespace = "http://www.webserviceX.NET/";
	String namespace = "http://tempuri.org/ConvertWeight/ConvertWeight";
	//private String url = "http://www.webservicex.net/ConvertWeight.asmx";
	private String url = "http://192.168.1.10/Ws/Service1.asmx";
	
	String SOAP_ACTION;
	SoapObject request = null, objMessages = null;
	SoapSerializationEnvelope envelope;
	AndroidHttpTransport androidHttpTransport;
	
	WebserviceCall() 
	{
		
	}

	
	/**
	 * Set Envelope
	 */
	protected void SetEnvelope() {
		
		try {
			
            // Creating SOAP envelope			
			envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			
			//You can comment that line if your web service is not .NET one.
			envelope.dotNet = true;
			
			envelope.setOutputSoapObject(request);
			androidHttpTransport = new AndroidHttpTransport(url);
			androidHttpTransport.debug = true;
			
		} catch (Exception e) {
			System.out.println("Soap Exception---->>>" + e.toString());	
		}
	}

	// MethodName variable is define for which webservice function  will call
	public String getConvertedWeight(String MethodName, String weight,
			String fromUnit, String toUnit) 
	  {
		
		try {
			SOAP_ACTION = namespace + MethodName;
			
			//Adding values to request object
			request = new SoapObject(namespace, MethodName);
			
			//Adding Double value to request object
			PropertyInfo weightProp =new PropertyInfo();
	        weightProp.setName("Weight");
	        weightProp.setValue(weight);
	        weightProp.setType(double.class);
	        request.addProperty(weightProp);
	        
	        //Adding String value to request object
	        request.addProperty("FromUnit", "" + fromUnit);
			request.addProperty("ToUnit", "" + toUnit);
			
			SetEnvelope();
			
			try {
				
				//SOAP calling webservice
				androidHttpTransport.call(SOAP_ACTION, envelope);
				
				//Got Webservice response
				String result = envelope.getResponse().toString();
				return result;
				
			} catch (Exception e) {
				// TODO: handle exception
				return e.toString();
			}
		} catch (Exception e) {
			// TODO: handle exception
			return e.toString();
		}
	}
	/************************************/
}

this is webservices call from android application
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;

namespace AndroidDemoService
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [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]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
       public string getConvertedWeight(String MethodName, String weight,String fromUnit, String toUnit)
        {
            string SA = "hey this is test";
            return SA;
        }
    }
}

above is the my web service in asp.net c#

i want to know how to run this local host
Posted
v2
Comments
Afzaal Ahmad Zeeshan 11-Apr-15 7:03am    
The local host would run on your Windows under IIS server, or under any other server if you're having a non-.NET web service.
What is the issue exactly?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900