【问题标题】:Android Connect to WCFAndroid 连接到 WCF
【发布时间】:2011-06-28 09:05:52
【问题描述】:

我无法连接到 WCF 服务,但我总是收到“启动超时已过期,放弃唤醒锁!” 这是服务文件:

<?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>

和我这样的android调用方法 编辑: 这是 Android 调用 WCF 使用 KSOAP2

 public SoapObject soap(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL) throws IOException, XmlPullParserException 
     {
        SoapObject request = new SoapObject(NAMESPACE, 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;
     }

这是我的 C# 方法:

   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;
        }

在我调用的活动中:

  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();
 }

错误是: 我收到这样的错误消息 **启动超时已过期,放弃唤醒锁!

** 已编辑: 我们怎样才能增加时间?请帮帮我

提前致谢;

【问题讨论】:

    标签: android wcf


    【解决方案1】:

    您正在发送没有任何 HTTP 标头或正文的空 POST 请求。基本 HTTP 绑定需要具有 SOAP 操作的有效 SOAP 请求,该操作用于确定调用的操作。无论如何,我认为这应该给你一些错误而不是超时。你至少可以从你的安卓设备上打开这个:http://192.168.1.11:7979/mytService?wsdl 吗?

    手动进行所有 SOAP 通信非常复杂。您应该使用一些可以帮助您使用 SOAP 服务的库 - 检查 kSoap2

    【讨论】:

    • 谢谢。我试过这个192.168.1.11:7979/mytService?wsdl 仍然遇到同样的错误。
    • 在这种情况下,您的服务未运行或您的安卓设备无法连接到托管该服务的计算机。
    • 我不熟悉 C# WCF。它没有在 IIS 服务器上运行。它是一个 Windows 组件。在我的组织中,他们通过 WCF 提供了我必须将数据推送到 android。服务正在运行。我想知道 C# WCF 而不在服务器内部运行我们可以访问方法吗?跨度>
    • 服务不会将数据推送到您的设备。您的设备必须从服务中提取数据。您的组件必须“运行”并且必须托管服务 - 将 192.168.1.11:7979/mytService192.168.1.11:7979/mytService?wsdl 放入浏览器。如果您遇到一些错误,您的服务没有运行。
    • 非常感谢。这项服务现在运行良好。如何访问 loadPassword_Executive(String) 方法?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 2011-10-27
    • 2013-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    相关资源
    最近更新 更多