ive spent about 10 hours over the past 2 days trying to figure this out and still cannot get it to work. i made a WCF service in VS2010 and i have it hosted in IIS. Im trying to call the service in Java in an Android project but i keep getting this error
o开发者_如何学Gorg.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:0 in java.io.InputStreamReader@4052b038)
here is my code:
package asdd.sd;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
public class AsdasdActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String nameSpace = "http://findmydroid.com/";
String methodName = "GetData";
String soapAction = "http://findmydroid.com/GetData";
String url = "http://10.0.2.2/FindMyDroid/Service1.svc";
SoapObject soapObject = new SoapObject(nameSpace, methodName);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet = true;
envelope.setOutputSoapObject(soapObject);
HttpTransportSE transport = new HttpTransportSE(url);
PropertyInfo pi = new PropertyInfo();
pi.setName("value");
pi.setValue(55);
soapObject.addProperty(pi);
try
{
transport.call(soapAction, envelope);
String dump = transport.requestDump;
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
boolean result = Boolean.parseBoolean(response.toString());
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
and here is the code for my web service:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace FindMyDroid.WCF
{
[ServiceContract(Namespace = "http://findmydroid.com/")]
public interface IService1
{
[OperationContract]
string GetData(int value);
// TODO: Add your service operations here
}
}
Here is the Service1 Class
namespace FindMyDroid.WCF
{
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
}
All i want to do is just test the service so i know that i can connect to it with Java if anybody can please help me out with this error. I have tried so many different examples from here (Stackoverflow) and other websites as well. I've tried by hosting the service in Visual Studio's ASP host and IIS. I've tried calling it with my external IP Address as well with no results.
From my experience, the XMLParser is trying to parse the response that it receives; though in this case it is possbile that the response it is receiving is in HTML format.
The XMLParser actually specifies that it does not recognise the type at:
position:END_DOCUMENT null@1:0
In my case the response was usually and error 500 or an error 404 HTML document. Once I had identified what the error response was, I was able to direct the call to the correct url and received the correct response.
精彩评论