错误的SOAPFault - - 使用kso​​ap2与WCF web服务的Andr​​oid故障code:'一:InternalServiceFault“ [英] Android with WCF web service using ksoap2 - error SoapFault - faultcode: 'a:InternalServiceFault'

查看:868
本文介绍了错误的SOAPFault - - 使用kso​​ap2与WCF web服务的Andr​​oid故障code:'一:InternalServiceFault“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个简单的项目使用kso​​ap2 WCF Web服务调用。但是,当它调用envelope.getResponse();它提供了错误说

错误: 的SOAPFault - 故障code:'一:InternalServiceFault在faultstring:服务器无法处理请求由于内部错误。有关错误的详细信息,无论是打开IncludeExceptionDetailInFaults(无论是从ServiceBehaviorAttribute或从配置行为)的服务器上,以发送异常信息返回给客户端,或者打开跟踪按在Microsoft .NET Framework 3.0 SDK文档并检查服务器跟踪日志。 faultactor:'空'的细节:空

 包testing.wcf;
进口java.io.IOException异常;
进口org.ksoap2.SoapEnvelope;
进口org.ksoap2.serialization.SoapObject;
进口org.ksoap2.serialization.SoapPrimitive;
进口org.ksoap2.serialization.SoapSerializationEnvelope;
进口org.ksoap2.transport.HttpTransportSE;
进口org.xmlpull.v1.XmlPullParserException;
进口org.xmlpull.v1.XmlSerializer;

进口android.os.Bundle;
进口android.os.StrictMode;
进口android.widget.TextView;
进口android.annotation.Sup pressLint;
进口android.app.Activity;

公共类MainActivity扩展活动
{
    私有静态最后弦乐strNAMESPACE =htt​​p://www.testing.co.in/TestingService/;
    私有静态最后字符串strURL =htt​​p://www.testing.co.in/TestingService/UserDetails.svc;
    私有静态最后弦乐strSOAP_ACTION =htt​​p://testing.co.in/TestingService/UserDetails/LoginDetails;
    私有静态最后弦乐strMETHOD_NAME =LoginDetails;
    TextView的电视;
    StringBuilder的某人;
    字符串strInputXML;

      @覆盖
    公共无效的onCreate(包savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
        电视=(TextView中)findViewById(R.id.testing);
        SB =新的StringBuilder();
            呼叫();
        tv.setText(sb.toString());
        //的setContentView(TV);

    }
    公共无效调用()
    {
         尝试
         {
             SoapObject请求=新SoapObject(strNAMESPACE,strMETHOD_NAME);

            串inputxml =&其中;?xml的版本=+\+1.0+\+编码=+\+UTF-8+\+&GT ; +< MOB> \ N'LT; PIN> 0000< / PIN> \ N'LT;登录ID>测试< /登录ID> \ N'LT; PNUMBER> 112233< / pNUMBER> \ N'LT;请求ID> LoginVal< /请求ID> \ñ< / MOB>中;

            request.addAttribute(strInputXML,inputxml);
            request.addAttribute(strOutputXML,);

                   SoapSerializationEnvelope包=新SoapSerializationEnvelope(SoapEnvelope.VER11);
             envelope.dotNet = TRUE;
             envelope.setOutputSoapObject(要求);

             HttpTransportSE androidHttpTransport =新HttpTransportSE(strURL);
             androidHttpTransport.call(strSOAP_ACTION,包);
             SoapPrimitive结果=(SoapPrimitive)envelope.getResponse();

             串resultData = result.toString();
             sb.append(resultData +\ N);
         }
         赶上(例外五)
         {
             sb.append(错误:\ n+ e.getMessage()+\ N);
         }
    }
}
 

在这里,我要发这样的要求

 < XML版本=1.0编码=UTF-8&GT?;
< PhoneData>
<针脚号> 0000< /针脚号>
<登录ID> HELLO< /登录ID>
<密码> 1234< / PASSWORD>
&其中; REQID> 0℃/ REQID>
< / PhoneData>
 

我的XML响应应该是

 < XML版本=1.0编码=UTF-8&GT?;
< PhoneData>
&其中; OTA&GT 1234所述; / OTA>
< / PhoneData>
 

解决方案

我后我的工作code为消费WCF(WCF的结合已是basicHttpBinding的!):

 私有静态最后弦乐NAMESPACE =htt​​p://tempuri.org/;
私有静态字符串URL =您的网址;

私有静态最后弦乐SOAP_ACTION_VALIDATION =IValidateUser_wcf /的ValidateUser;
私有静态最后弦乐VALIDATION_METHOD =的ValidateUser;

公共布尔validateUser_WCF(字符串用户名,字符串密码){

    SoapSerializationEnvelope信封= NULL;
    SoapObject请求= NULL;
    HttpTransportSE httpTransportSE = NULL;

    尝试 {
        要求=新SoapObject(命名空间VALIDATION_METHOD);
        request.addProperty(用户名,用户名);
        request.addProperty(密码,密码);

        信封=新SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = TRUE;
        envelope.setOutputSoapObject(要求);

            //////////////////////////////
            //这里你可以,如果你想添加一个Header元素
        元素[]头=新的元素[1];

        标题[0] =新元素()的createElement(NAMESPACE_INFOCAD,A1)。
        头[0] .addChild(Node.TEXTHeaderTextContent);

        envelope.headerOut =报头;
            //////////////////////////////

        httpTransportSE =新HttpTransportSE(URL + VALIDATION_URI,10 * 10000); //第二个参数是超时
        httpTransportSE.debug = TRUE;
        httpTransportSE.setXmlVersionTag(&所述;?xml的版本= \1.0 \编码= \utf-8的\>?);
        httpTransportSE.call空间(namespace + SOAP_ACTION_VALIDATION,包);

            //如果响应是一个简单的文本结果,你可以调用SoapPrimitive,如果不是,你必须调用SoapObject结果和浏览响应的树像一个XML文件
        SoapPrimitive结果=(SoapPrimitive)envelope.getResponse();

        //获取数据。
        串textResult = result.toString();
        Log.i(textResult,textResult);

                    返回true;

    }赶上(例外五){
        // TODO:处理异常
        e.printStackTrace();
    }最后{
                 //在这里你可以在日志中看到什么是你发送请求的,什么是收到响应
                Log.i(的getClass()getSimpleName(),requestDump:+ httpTransportSE.requestDump。);
                Log.i(的getClass()getSimpleName(),responseDump:+ httpTransportSE.responseDump。);
    }

    返回false;
}
 

希望我的code可以帮助你:)。它工作在100%

I have done a simple project to call wcf web service using ksoap2. But when it calls envelope.getResponse(); it gives error saying

Error: SoapFault - faultcode: 'a:InternalServiceFault' faultstring: 'The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.' faultactor: 'null' detail: null

package testing.wcf;
import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;

import android.os.Bundle;
import android.os.StrictMode;
import android.widget.TextView;
import android.annotation.SuppressLint;
import android.app.Activity;

public class MainActivity extends Activity 
{
    private static final String strNAMESPACE = "http://www.testing.co.in/TestingService/";
    private static final String strURL = "http://www.testing.co.in/TestingService/UserDetails.svc";
    private static final String strSOAP_ACTION = "http://testing.co.in/TestingService/UserDetails/LoginDetails";
    private static final String strMETHOD_NAME = "LoginDetails";
    TextView tv;
    StringBuilder sb;
    String strInputXML;

      @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv = (TextView)findViewById(R.id.testing);
        sb = new StringBuilder();       
            Call();
        tv.setText(sb.toString());
        //setContentView(tv);

    }
    public void Call()
    {
         try 
         {
             SoapObject request = new SoapObject(strNAMESPACE, strMETHOD_NAME);

            String inputxml = "<?xml version="+"\""+"1.0"+"\""+" encoding="+"\""+"utf-8"+"\""+" ?>" +"<MOB> \n  <PIN>0000</PIN> \n  <LOGINID>TEST</LOGINID> \n  <PNUMBER>112233</pNUMBER> \n  <REQUESTID>LoginVal</REQUESTID> \n </MOB>";

            request.addAttribute("strInputXML", inputxml);
            request.addAttribute("strOutputXML","");

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

             HttpTransportSE androidHttpTransport = new HttpTransportSE(strURL);
             androidHttpTransport.call(strSOAP_ACTION, envelope);
             SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

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

Here I want to send the request like this

<?xml version="1.0" encoding="utf-8" ?> 
<PhoneData>
<PINNO>0000</PINNO>
<LOGINID>HELLO</LOGINID>
<PASSWORD>1234</PASSWORD>
<REQID>0</REQID>
</PhoneData>

My respond XML should be

<?xml version="1.0" encoding="utf-8" ?> 
<PhoneData>
<OTA>1234</OTA>
</PhoneData>

解决方案

I post my working code for consuming a WCF (binding of WCF has to be basicHttpBinding!):

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

private static final String SOAP_ACTION_VALIDATION = "IValidateUser_wcf/ValidateUser";
private static final String VALIDATION_METHOD = "ValidateUser";

public boolean validateUser_WCF(String username, String password){

    SoapSerializationEnvelope envelope = null;
    SoapObject request = null;
    HttpTransportSE httpTransportSE = null;

    try {
        request = new SoapObject(NAMESPACE, VALIDATION_METHOD);
        request.addProperty("username", username);
        request.addProperty("password", password);

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

            //////////////////////////////                               
            // here you can add a HEADER element if you want
        Element[] header = new Element[1];  

        header[0] = new Element().createElement(NAMESPACE_INFOCAD, "a1");                
        header[0].addChild(Node.TEXT, "HeaderTextContent");

        envelope.headerOut = header;
            //////////////////////////////                               

        httpTransportSE = new HttpTransportSE(URL+VALIDATION_URI, 10*10000); // second parameter is timeout
        httpTransportSE.debug = true;
        httpTransportSE.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        httpTransportSE.call(NAMESPACE+SOAP_ACTION_VALIDATION, envelope);

            // if response is a simple text result, you can call SoapPrimitive, if not, you have to call SoapObject result and navigate in response's tree like an xml file
        SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

        //To get the data.
        String textResult = result.toString();
        Log.i("textResult", textResult); 

                    return true;

    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }finally{
                 // here you can see in LOG what is request you send and what is response received
                Log.i(getClass().getSimpleName(),"requestDump : "+httpTransportSE.requestDump);
                Log.i(getClass().getSimpleName(),"responseDump : "+httpTransportSE.responseDump);
    }

    return false;
}

Hope my code can help you :). It works at 100%

这篇关于错误的SOAPFault - - 使用kso​​ap2与WCF web服务的Andr​​oid故障code:'一:InternalServiceFault“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆