Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将中的值保存到android中的webservice?_Android_.net_Web Services - Fatal编程技术网

如何将中的值保存到android中的webservice?

如何将中的值保存到android中的webservice?,android,.net,web-services,Android,.net,Web Services,我无法将值保存到.net中的Web服务器中。我使用了下面的代码,但在emulator中得到了follow-in错误..即 Server was unable to process request---> cannot insert the value null into column 'Name', table 'MyWorldApp.dbo.tbl_UserRegistration';column doesnot allow nulls.INSERT fails. The Stateme

我无法将值保存到.net中的Web服务器中。我使用了下面的代码,但在emulator中得到了follow-in错误..即

Server was unable to process request---> cannot insert the value null into column 'Name', table 'MyWorldApp.dbo.tbl_UserRegistration';column doesnot allow nulls.INSERT fails. The Statement has been terminated.
我已使用以下链接:

我的代码是:

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.*;
    import android.os.*;
    import android.util.Log;
    import android.widget.TextView;

    public class MyworldActivity extends Activity {
        /** Called when the activity is first created. */

        private static final String SOAP_ACTION = "http://localhost/service1/InsertUsertRegistrationDetails";

        private static final String METHOD_NAME = "POST";

        private static final String NAMESPACE = "http://localhost/service1";
        private static final String URL = "http://113.193.181.53/MyWorldApp/Service1.asmx";



        TextView tv;

        @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);

                request.addProperty("Name", "'Rajapandian'");
                request.addProperty("UserName", "Rajapandian");
                request.addProperty("Password", "123");
                request.addProperty("MobileNumber", "456");
                request.addProperty("EmailID", "Rajapandian@gmail.com");
                request.addProperty("image", "http://www.thehindu.com/multimedia/dynamic/00880/INDIA_CORRUPTION_PR_880168f.jpg");
                Log.e("success","success");
                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.dotNet=true;
                envelope.setOutputSoapObject(request);

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

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

                tv.setText(result.toString());
            } catch (Exception e) {
                tv.setText(e.getMessage());
                }
        }
    }
谁能告诉我哪里做错了


提前感谢..

这是解决方案, 在本例中,我使用了get方法。只需在url字符串中传递变量即可

String url = "http://113.193.181.53/MyWorldApp/Service1.asmx/InsertUsertRegistrationDetails?Name=string&UserName=string&Password=string&MobileNumber=string&EmailID=string&image=string"

URL sourceUrl = new URL(url);
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();
            Handler1 dataHandler = new Handler1();
            xr.setContentHandler(dataHandler);
            xr.parse(new InputSource(sourceUrl.openStream()));
            Dataset dataset = dataHandler.getParsednewJobdtl_DataSet();
数据集:

package com.RecordingApp;

public class AuthDataset {



    private String booleanx = null;

    public void setbooleanx (String booleanx ) {
        this.booleanx = booleanx ;
    }

    public String getbooleanx () {
        return booleanx ;
    }


}
处理程序:

package com.RecordingApp;

import java.util.ArrayList;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class AuthHandler extends DefaultHandler {
    boolean int1 = false;

    ArrayList ar1 = new ArrayList();

    ArrayList br1 = new ArrayList();

    private AuthDataset mysitelist = new AuthDataset();

    public AuthDataset getParsednewJobdtl_DataSet() {
        return this.mysitelist;
    }

    public void startDocument() throws SAXException {
        this.mysitelist = new AuthDataset();
    }

    @Override
    public void endDocument() throws SAXException {
    }

    // ***********************Start Element********************
    @Override
    public void startElement(String namespaceURI, String localName,
            String qName, Attributes atts) throws SAXException {
        if (localName.equals("boolean ")) {
            this.int1 = true;
        }

    }

    // ***********************End element********************
    @Override
    public void endElement(String namespaceURI, String localName, String qName)
            throws SAXException {
        if (localName.equals("boolean ")) {
            this.int1 = false;

        }
    }

    // ***********************character********************
    @Override
    public void characters(char ch[], int start, int length) {
        if (this.int1) {
            mysitelist.setbooleanx(new String(ch, start, length));
            ar1.add(new String(ch, start, length));
            setbooleanx (ar1);

        }

    }

    public void setbooleanx (ArrayList ar1) {
        this.br1 = ar1;
    }
    public ArrayList getbooleanx () {

        return br1;
    }

}
服务器无法处理请求--->无法插入空值 进入“Name”列,表“MyWorldApp.dbo.tbl_UserRegistration”;柱 不允许为空。插入失败。声明已终止

以上是你的错误。 您正在字段名称中插入空值,并且名称设置为不接受空值

  • 所以修改数据库表
  • 或强制在名称字段中添加非空值
编辑

将值发布到Web服务的方法是将空值发送到服务器,而不是

Object result = (Object)envelope.getResponse();
试试这个

SoapObject response= (SoapObject) envelope.bodyIn;

谢谢你。。。我如何从中检索存储的值我无法这样做,因为轮到你做某事了。。。如果你有什么问题,告诉我