使用kso​​ap2的WCF Web服务的Android – 错误SoapFault – faultcode:’a:InternalServiceFault’

使用kso​​ap2的WCF Web服务的Android – 错误SoapFault – faultcode:’a:InternalServiceFault’,第1张

概述我做了一个简单的项目,使用kso​​ap2调用wcf Web服务.但是当它调用envelope.getResponse();它给出了错误的说法 错误: SoapFault – faultcode:’a:InternalServiceFault’faultstring:’由于内部错误,服务器无法处理请求.有关错误的更多信息,请在服务器上启用IncludeExceptionDetailInFaults 我做了一个简单的项目,使用kso​​ap2调用wcf Web服务.但是当它调用envelope.getResponse();它给出了错误的说法

错误:
SoapFault – faultcode:’a:InternalServiceFault’faultstring:’由于内部错误,服务器无法处理请求.有关错误的更多信息,请在服务器上启用IncludeExceptionDetailinFaults(来自ServiceBehaviorAttribute或配置行为)以将异常信息发送回客户端,或者根据Microsoft .NET Framework 3.0 SDK文档启用跟踪并检查服务器跟踪日志. 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");         }           }}

在这里,我想发送这样的请求

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

我的回应应该是XML

<?xml version="1.0" enCoding="utf-8" ?> <PhoneData><OTA>1234</OTA></PhoneData>
解决方法 我发布我的工作代码以消耗WCF(WCF的绑定必须是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;}

希望我的代码可以帮助你:).它的工作率为100%

总结

以上是内存溢出为你收集整理的使用kso​​ap2的WCF Web服务的Android – 错误SoapFault – faultcode:’a:InternalServiceFault’全部内容,希望文章能够帮你解决使用kso​​ap2的WCF Web服务的Android – 错误SoapFault – faultcode:’a:InternalServiceFault’所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1103801.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存