views:

1466

answers:

4

Hi all,

Here is my code

import org.ksoap2.*;
import org.ksoap2.serialization.*;
import org.ksoap2.transport.*;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class ksop2test extends Activity {
 /** Called when the activity is first created. */


 private static final String METHOD_NAME = "SayHello";
// private static final String METHOD_NAME = "HelloWorld";

 private static final String NAMESPACE = "http://tempuri.org";
// private static final String NAMESPACE = "http://tempuri.org";

 private static final String URL = "http://192.168.0.2:8080/HelloWCF/Service1.svc";
// private static final String URL = "http://192.168.0.2:8080/webservice1/Service1.asmx";

 final String SOAP_ACTION = "http://tempuri.org/IService1/SayHello";
// final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
 TextView tv;
 StringBuilder sb;



 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  tv = new TextView(this);
  sb = new StringBuilder();
  call();
  tv.setText(sb.toString());
  setContentView(tv);
 }

 public void call() {
  try {

   SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

   request.addProperty("name", "Qing");

   SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
     SoapEnvelope.VER11);
   envelope.dotNet = true;
   envelope.setOutputSoapObject(request);


   HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
   androidHttpTransport.call(SOAP_ACTION, envelope);
   sb.append(envelope.toString() + "\n");//cannot get the xml request send
   SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

   //to get the data
   String resultData = result.toString();
   // 0 is the first object of data 


   sb.append(resultData + "\n");
  } catch (Exception e) {
   sb.append("Error:\n" + e.getMessage() + "\n");
  }

 }

}

I can successfully access .asmx service, but when I try to call a wcf service the virtual machine said : Error: expected:END_TAG{http://schemas.xmlsoap.org/soap/envelope/}Body(position:END_TAG@1:712 in java.io.InputStreamReader@43ba6798

How to print what the request send?

Here is the wcf wsdl:

    <wsdl:definitions name="Service1" targetNamespace="http://tempuri.org/"&gt;
−
<wsdl:types>
−
<xsd:schema targetNamespace="http://tempuri.org/Imports"&gt;
<xsd:import schemaLocation="http://para-bj.para.local:8080/HelloWCF/Service1.svc?xsd=xsd0" namespace="http://tempuri.org/"/&gt;
<xsd:import schemaLocation="http://para-bj.para.local:8080/HelloWCF/Service1.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/&gt;
</xsd:schema>
</wsdl:types>
−
<wsdl:message name="IService1_SayHello_InputMessage">
<wsdl:part name="parameters" element="tns:SayHello"/>
</wsdl:message>
−
<wsdl:message name="IService1_SayHello_OutputMessage">
<wsdl:part name="parameters" element="tns:SayHelloResponse"/>
</wsdl:message>
−
<wsdl:portType name="IService1">
−
<wsdl:operation name="SayHello">
<wsdl:input wsaw:Action="http://tempuri.org/IService1/SayHello" message="tns:IService1_SayHello_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/IService1/SayHelloResponse" message="tns:IService1_SayHello_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
−
<wsdl:binding name="BasicHttpBinding_IService1" type="tns:IService1">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/&gt;
−
<wsdl:operation name="SayHello">
<soap:operation soapAction="http://tempuri.org/IService1/SayHello" style="document"/>
−
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
−
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
−
<wsdl:service name="Service1">
−
<wsdl:port name="BasicHttpBinding_IService1" binding="tns:BasicHttpBinding_IService1">
<soap:address location="http://para-bj.para.local:8080/HelloWCF/Service1.svc"/&gt;
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

It uses in tag and the asmx uses in tag what's the difference? Thanks.

-Qing

A: 

In "theory" wcf with basic http binding and asmx should work the same.

It could be something to do with how your WCF service is configured.

We get a similar problem if we configure TransferMode Streamed on the client and Buffered on the server. Although not sure if this is relevant in your case.

Shiraz Bhaiji
A: 

finally I got it to work because the namespace missed a "/" in the end ,

following is my code

package cn.qing.ksop2test;

import java.io.Writer;

import org.ksoap2.; import org.ksoap2.serialization.; import org.ksoap2.transport.*; import org.xmlpull.v1.XmlSerializer;

import android.app.Activity; import android.os.Bundle; import android.util.Xml; import android.widget.TextView;

public class ksop2test extends Activity { /** Called when the activity is first created. */

private static final String METHOD_NAME = "HelloWorldRequest";

// private static final String METHOD_NAME = "HelloWorld";

private static final String NAMESPACE = "http://tempuri.org/";

// private static final String NAMESPACE = "http://tempuri.org";

private static final String URL = "http://192.168.0.2:8080/HelloWCF/Service1.svc";

// private static final String URL = "http://192.168.0.2:8080/webservice1/Service1.asmx";

final String SOAP_ACTION = "http://tempuri.org/IService1/HelloWorld";

// final String SOAP_ACTION = "http://tempuri.org/HelloWorld"; TextView tv; StringBuilder sb; private XmlSerializer writer;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    tv = new TextView(this);
    sb = new StringBuilder();
    call();
    tv.setText(sb.toString());
    setContentView(tv);
}

public void call() {
    try {

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        request.addProperty("Name", "Qing");

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);


        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.call(SOAP_ACTION, envelope);
        SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

        //to get the data
        String resultData = result.toString();
        // 0 is the first object of data 


        sb.append(resultData + "\n");
    } catch (Exception e) {
        sb.append("Error:\n" + e.getMessage() + "\n");
    }

}

}

Qing
A: 

I have the following setup for my ksoap2, but it keeps saying can't serialize. What am I missing?

private static final String SOAP_ACTION = "AuthenticateUser";
private static final String METHOD_NAME = "AuthenticatdUser";
private static final String NAMESPACE="MobileWebServices.asmx";
private static final String URL="http://10.109.126.158:7015/MobileWebServices.asmx";

It is an external facing web service hosted on one of our servers for our technicians to use. It was written in ASP .NET 2008. The NameSpace of the project is MobileWebServices. AuthenticateUser is the WebMethod within the web service that I am trying to call. http://10.109.126.158:7015 is where the user goes in order to access the web service.

Any help would be greatly appreciated.

Thanks

crusso
A: 

I'm using

private static final String SOAP_ACTION = "http://tempuri.org/IContact/GetContactCount";
private static final String METHOD_NAME = "GetContactCount";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://xxx.xxx.com/Contacts/ContactsService.Contacts.svc";

So maybe the problem is in your SOAP action.

Also is the spelling on your method name correct ie AuthenticatdUser?

Leo Moore