【问题标题】:calling .net web service from android not working从android调用.net web服务不起作用
【发布时间】:2011-01-13 14:02:33
【问题描述】:

我正在从我的 android 应用程序调用 .net Web 服务,但没有运气。 这是我的代码:

我的包裹:

package com.reza;

import android.app.Activity;
import android.os.Bundle;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.widget.TextView;

班级:

public class callWebservice extends Activity {
     private static final String METHOD_NAME = "HelloWorld";

     private static final String NAMESPACE = "http://tempuri.org/";
     private static final String URL = "http://service.screwedmind.com/LocalBusiness.asmx";
     private static final String SOAP_ACTION = null;
     TextView tv;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv=(TextView)findViewById(R.id.text1);
        call();
    }
    public void call()
    {
            try {

            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

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

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

            String result=(String)envelope.getResponse();

            tv.setText(result);
            } 
            catch (Exception e) {
                tv.setText("error occured..");
            }
    }
}

当我运行这个程序时,我看到我的错误文本是 "error occured..." 任何人都可以指导我做错了什么。

【问题讨论】:

    标签: .net android web-services


    【解决方案1】:

    “发生错误..”是您的错误消息,写tv.setText(e.toString());,您在那里看到什么消息?

    【讨论】:

    • 它是一条丑陋的消息。-----SoapFault-faultcode:'soap:Client' faultstring:'System.web.services.protocols.soapexception:Server 没有识别 HTTP 的值标头 SOAPAction:HelloWorld。在 System.web.services.protocols.soap11ServerProtocolHelper.RouteRequest() 在 System.web.services.protocols.soapServerProtocol.RouteRequest(SoapServerMessage 消息) 在 web.services.protocols.soapServerProtocol.Initialize() 在 web.services.protocols.soapServerProtocol .SetContext(Type type, HttpContext context,HttpRequest request,HttpResponse response) at ----it继续..
    • 重要的一点是Server did not not recognize the value of HTTP Header SOAPAction,检查是因为您的 SOAPAction 为空。尝试@bigstones 的建议来设置 SOAP_ACTION。
    • 另外,消息的其余部分是一个堆栈跟踪,显示错误发生的位置以及当时堆栈的状态。
    【解决方案2】:

    你可能只需要设置SOAP_ACTION = NAMESPACE + METHOD_NAME

    【讨论】:

      【解决方案3】:

      您应该更改 SOAP_ACTION = NAMESPACE + METHOD_NAME

      【讨论】:

      • 此解决方案已发布
      猜你喜欢
      • 1970-01-01
      • 2016-11-03
      • 2015-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多