服务器无法读取参数,同时使一个Web服务连接 [英] Server not able to read parameters while making a webservice connection

查看:141
本文介绍了服务器无法读取参数,同时使一个Web服务连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我连接到.NET Web服务使用下面code,我能够连接并获得server.I不完全反应我添加用户标识已与'1'参数具有类型string.The问题的值是'服务器是不是能看懂我送的请求参数都'。我是不知道什么是错的我side.I已连接的Web服务请求和响应,我的code。

和我的Andr​​oid连接code

 私有类AsyncCallWS扩展的AsyncTask<字符串,太虚,太虚> {
        @覆盖
        保护无效doInBackground(字符串... PARAMS){
            //调用Web服务
        displayText = WebService.invokeHelloWorldWS(EDITTEXT,GetReminder);
        返回null;
        }

        @覆盖
        保护无效onPostExecute(无效的结果){
            //设置响应
            tv.setText(displayText);
            //使进度无形
            pg.setVisibility(View.INVISIBLE);
        }

        @覆盖
        在preExecute保护无效(){
            //使进度无形
            pg.setVisibility(View.VISIBLE);
        }

        @覆盖
        保护无效onProgressUpdate(空...值){
        }

    }
 

Web服务在这里被调用。

 公共类的WebService {
    //什么是web服务的命名空间?
    私有静态字符串NAMESPACE =htt​​p://tempuri.org;
    // Webservice的网址
私有静态字符串URL =htt​​p://1.3.44.5:8080/csmmobileapi/service.asmx;
    // SOAP动作URI ???
    私有静态字符串SOAP_ACTION =htt​​p://tempuri.org/GetReminder;
    私有静态最后字符串变量= NULL;
    公共静态字符串invokeHelloWorldWS(字符串名称,字符串webMethName)
{
        布尔结果= FALSE;
        字符串resTxt = NULL;
        //创建请求
        HttpTransportSE androidHttpTransport =新HttpTransportSE(URL);
        SoapSerializationEnvelope包=新SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        SoapObject请求=新SoapObject(命名空间webMethName);
        envelope.setOutputSoapObject(要求);
        androidHttpTransport.debug = TRUE;
        //物业持有输入参数
        的PropertyInfo sayHelloPI =新的PropertyInfo();
        //设置名称
        sayHelloPI.setName(用户ID);
        //设置值
        sayHelloPI.setValue(1);
        //设置的dataType
        sayHelloPI.setType(为String.class);
        //添加属性Request对象
       request.addProperty(sayHelloPI);
        //设置信封的dotNet
        envelope.dotNet = TRUE;
        尝试 {
            //调用Web服务
            androidHttpTransport.call(SOAP_ACTION,包);
            //得到响应
            字符串响应= androidHttpTransport.responseDump;
            Log.d(结果---,response.toString());
           //试图与SoapObject和SoapPrimitive
            SoapObject OBJ =(SoapObject)envelope.getResponse();
            Log.d(结果---,OBJ);
            的System.out.println(物镜---->中+ obj.toString());
}
 

解决方案

做了一件非常愚蠢的错误,我发现了这样多的试n错误下班后.., 私有静态字符串NAMESPACE =htt​​p://tempuri.org; 更改为私有静态字符串NAMESPACE =htt​​p://tempuri.org/ ; 和一切工作顺利

I am connecting to .net webservice using below code,i am able to connect and get incomplete response from server.I am adding userId has parameter with '1' has value of type string.The issue is 'server is not able to read the parameters at all i am sending in request' .I am not sure if something is wrong on my side.I have attached the webservice request and response and my code.

and my android connecting code

private class AsyncCallWS extends AsyncTask<String, Void, Void> {
        @Override
        protected Void doInBackground(String... params) {
            //Invoke webservice
        displayText=WebService.invokeHelloWorldWS(editText,"GetReminder");
        return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            //Set response
            tv.setText(displayText);
            //Make ProgressBar invisible
            pg.setVisibility(View.INVISIBLE);
        }

        @Override
        protected void onPreExecute() {
            //Make ProgressBar invisible
            pg.setVisibility(View.VISIBLE);
        }

        @Override
        protected void onProgressUpdate(Void... values) {
        }

    }

webservice called here.

public class WebService {
    //What is the Namespace of the Webservice ??
    private static String NAMESPACE = "http://tempuri.org";
    //Webservice URL
private static String URL = "http://1.3.44.5:8080/csmmobileapi/service.asmx";
    //SOAP Action URI ???
    private static String SOAP_ACTION = "http://tempuri.org/GetReminder";
    private  static final String TAG=null;
    public static String invokeHelloWorldWS(String name, String webMethName)  
{
        boolean result=false;
        String resTxt = null;
        // Create request
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        SoapObject request = new SoapObject(NAMESPACE, webMethName);
        envelope.setOutputSoapObject(request);
        androidHttpTransport.debug=true;
        // Property which holds input parameters
        PropertyInfo sayHelloPI = new PropertyInfo();
        // Set Name
        sayHelloPI.setName("UserId");
        // Set Value
        sayHelloPI.setValue("1");
        // Set dataType
        sayHelloPI.setType(String.class);
        // Add the property to request object
       request.addProperty(sayHelloPI);
        //Set envelope as dotNet
        envelope.dotNet = true;
        try {
            // Invoke web service
            androidHttpTransport.call(SOAP_ACTION, envelope);
            // Get the response
            String response=androidHttpTransport.responseDump;
            Log.d("Result --- ", response.toString() );
           //tried with SoapObject and SoapPrimitive
            SoapObject obj=(SoapObject)envelope.getResponse();
            Log.d("Result --- ", obj);
            System.out.println("obj---->" + obj.toString());
}

解决方案

Did a very silly mistake,i found out after doing so much trial n error work.., private static String NAMESPACE = "http://tempuri.org"; changed to private static String NAMESPACE = "http://tempuri.org/"; and everything worked well.

这篇关于服务器无法读取参数,同时使一个Web服务连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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