Android Connect to WCF
I could not connect to WCF service , but it alsways i get "Launch timeout has expired, giving up wake lock!" This is service file :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
......
</connectionStrings>
<appSettings>
<add key="HO" value=""/>
<add key="AutoUpdatePath" value="E:\AutoUpdate"/>
</appSettings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="NewBinding0" maxBufferSize="2000000" maxReceivedMessageSize="2000000">
<readerQuotas maxStringContentLength="2000000" maxArrayLength="2000000" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="NewBehavior" name="XONT.Common.Data.PDAServiceBLL.MyPDAService">
<endpoint address="http://192.168.1.11:7979/mytService" binding="basicHttpBinding"
bindingConfiguration="NewBinding0" contract="My.Common.Data.PDAServiceBLL.MyPDAService"/>
<host>
<baseAddresses>
<add baseAddress="http://192.168.1.11:7979/mytService"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
and my android calling method like this EDIT: Here is Android calling WCF usig KSOAP2
public SoapObject soap(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL) throws IOException, XmlPullParserException
{
SoapObject request = new SoapObject(NAME开发者_JS百科SPACE, METHOD_NAME); //set up request
request.addProperty("strExec", "WAT2"); //variable name, value. I got the variable name, from the wsdl file!
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //put all required data into a soap envelope
envelope.setOutputSoapObject(request); //prepare request
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
httpTransport.debug = true; //this is optional, use it if you don't want to use a packet sniffer to check what the sent
//message was (httpTransport.requestDump)
httpTransport.call(SOAP_ACTION, envelope); //send request
SoapObject result=(SoapObject)envelope.getResponse(); //get response
return result;
}
This is my C# method:
namespace My.Common.Data.PDAServiceDAL
{
public class MyPDAServiceDAL
{
EcecutiveCode = "";
sqlConnection = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
}
public List<string> loadPassword_Executive(string strExec)
{
EcecutiveCode = strExec;
sqlCon = new SqlConnection(sqlConnection);
List<string> list = new List<string>();
SqlCommand com;
SqlDataReader dr;
try
{
string sql = "select Password,BusinessUnit,PrimaryTerritoryCode,DefaultSalesWarehouse,DefaultSalesLocation from RD.Executive where ExecutiveCode = '" + strExec + "'";
com = new SqlCommand(sql, sqlCon);
sqlCon.Open();
dr = com.ExecuteReader();
if (dr.Read())
{
list.Add(dr[0].ToString());
list.Add(dr[1].ToString());
list.Add(dr[2].ToString());
list.Add(dr[3].ToString());
list.Add(dr[4].ToString());
}
}
catch (Exception e)
{
WriteToLog(e);
throw e;
}
finally
{
sqlCon.Close();
//dr.Close();
//dr.Dispose();
}
return list;
}
and in Activity i called:
try {
SoapObject result=soap(METHOD_NAME, SOAP_ACTION, NAMESPACE, APPURL);
Log.w("log_tag",result.getPropertyCount()+ "=====" + result.getProperty(0).toString());
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
Error is : I got error message Like this **Launch timeout has expired, giving up wake lock!
** Edited: How we can increase the time? please help me
Thanks in advance;
You are sending empty POST request without any HTTP header or body. Basic HTTP binding expects valid SOAP request with SOAP action which is used to determine called operation. Anyway I think that should give your some error instead of timeout. Can you at least open this from your android device: http://192.168.1.11:7979/mytService?wsdl
?
Doing all SOAP communication manually is quite complex. You should use some library which will help you consuming SOAP services - check kSoap2.
精彩评论