首页 新闻 会员 周边 捐助

webService 获得支持查询邮政编码的城市和地区

0
悬赏园豆:5 [已解决问题] 解决于 2012-07-26 10:14

// 命名空间
 private String NAMESPACE = "http://WebXml.com.cn/";
 // 访问的方法名
 private String METHOD_NAME = "getSupportProvinceCity";
 // 命名空间+方法名
 private String SOAP_ACTION = "http://WebXml.com.cn/getSupportProvinceCity";
 // 服务的url
 private String serviceUrl = "http://webservice.webxml.com.cn/WebServices/ChinaZipSearchWebService.asmx";

 

利用这几个变量实现邮政编码的支持城市的查询!!!拜托了,很急!!

mitty的主页 mitty | 菜鸟二级 | 园豆:207
提问于:2012-07-25 11:56
< >
分享
最佳答案
0

添加web引用不行吗?

收获园豆:5
Tom.汤 | 老鸟四级 |园豆:3058 | 2012-07-25 13:14

最主要的是得到的DataSet我没法下手,想要分别得到省份和地区。能给我说下吗?尽量有实际的代码!!!

mitty | 园豆:207 (菜鸟二级) | 2012-07-25 13:58

@mitty: 

   ServiceReference1.ChinaZipSearchWebServiceSoapClient client = new WindowsFormsApplication3.ServiceReference1.ChinaZipSearchWebServiceSoapClient();
            DataSet ds = client.getSupportProvinceCity();
            dataGridView1.DataSource = ds.Tables[0];

我试验了下 可以的

下面是我的app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="ChinaZipSearchWebServiceSoap" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="6553600" maxBufferPoolSize="52428800" maxReceivedMessageSize="6553600"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="819200" maxArrayLength="16384"
                        maxBytesPerRead="409600" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
            <customBinding>
                <binding name="ChinaZipSearchWebServiceSoap12">
                    <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                        messageVersion="Soap12" writeEncoding="utf-8">
                        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    </textMessageEncoding>
                    <httpTransport manualAddressing="false" maxBufferPoolSize="52428800"
                        maxReceivedMessageSize="6553600" allowCookies="false" authenticationScheme="Anonymous"
                        bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                        keepAliveEnabled="true" maxBufferSize="6553600" proxyAuthenticationScheme="Anonymous"
                        realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                        useDefaultWebProxy="true" />
                </binding>
            </customBinding>
        </bindings>
        <client>
            <endpoint address="http://webservice.webxml.com.cn/WebServices/ChinaZipSearchWebService.asmx"
                binding="basicHttpBinding" bindingConfiguration="ChinaZipSearchWebServiceSoap"
                contract="ServiceReference1.ChinaZipSearchWebServiceSoap"
                name="ChinaZipSearchWebServiceSoap" />
        </client>
    </system.serviceModel>
</configuration>

Tom.汤 | 园豆:3058 (老鸟四级) | 2012-07-25 16:42
其他回答(2)
0

1.添加服务引用:http://webservice.webxml.com.cn/WebServices/ChinaZipSearchWebService.asmx

2.调用:getAddressByZipCode

3.OK 返回的是你传入的邮政编码的地方,可以到村子的 ,不是您说的“最主要的是得到的DataSet我没法下手

4.赶紧动手吧

5.成功后,多给我点豆豆吧!

祝你好运!!

Angkor--:-- | 园豆:1086 (小虾三级) | 2012-07-25 14:07

我要用的服务和方法是规定好的!!!!不能修改

支持(0) 反对(0) mitty | 园豆:207 (菜鸟二级) | 2012-07-25 14:25

@mitty: 不知所云

支持(0) 反对(0) Angkor--:-- | 园豆:1086 (小虾三级) | 2012-07-25 15:20

我们经理规定用"http://webservice.webxml.com.cn/WebServices/ChinaZipSearchWebService.asmx";这个url的getSupportProvinceCity这个方法,不能用你说的那个!!!

支持(0) 反对(0) mitty | 园豆:207 (菜鸟二级) | 2012-07-25 15:22

@mitty:  Why? 有什么坏处吗?你们经理是何方高僧??求指教。。。。。!

支持(0) 反对(0) Angkor--:-- | 园豆:1086 (小虾三级) | 2012-07-25 18:32

虽然 我没用到你说的,但还是谢了

支持(0) 反对(0) mitty | 园豆:207 (菜鸟二级) | 2012-07-26 10:15
0
// 命名空间
    private String NAMESPACE = "http://WebXml.com.cn/";
    // 访问的方法名
    private String METHOD_NAME = "getSupportProvinceCity";
    // 命名空间+方法名
    private String SOAP_ACTION = "http://WebXml.com.cn/getSupportProvinceCity";
    // 服务的url
    private String serviceUrl = "http://webservice.webxml.com.cn/WebServices/ChinaZipSearchWebService.asmx";
    private Button search;
    private ArrayList<HashMap<String, String>> province_city = new ArrayList<HashMap<String, String>>();
    private SimpleAdapter sa;
    private ListView list;
    private HashMap<String, String> hm;
    private ProgressDialog progressDialog = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.country_down_province_and_city_layout);
        search = (Button) findViewById(R.id.w_countryandprovince);
        list = (ListView) findViewById(R.id.w_provinceList);
        search.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // 显示进度条对话框
                progressDialog = ProgressDialog.show(
                        CountryDownProvinceAndCity.this, "请稍等...", "获取数据中...",
                        true);
                // 执行异步任务
                new NetAsyncTask().execute(serviceUrl);
            }
        });
    }

    class NetAsyncTask extends
            AsyncTask<String, String, ArrayList<HashMap<String, String>>> {

        @Override
        protected ArrayList<HashMap<String, String>> doInBackground(
                String... params) {
            return getResult();
        }

        @Override
        protected void onPostExecute(ArrayList<HashMap<String, String>> result) {
            // 将list列表添加到适配器中并显示
            sa = new SimpleAdapter(CountryDownProvinceAndCity.this,
                    province_city, R.layout.province_city, new String[] {
                            "province", "cityname" }, new int[] {
                            R.id.w_provinceItem, R.id.w_countryItem });
            list.setAdapter(sa);
            // 将进度条对话框设为不可见状态
            progressDialog.dismiss();
            super.onPostExecute(result);
        }

    }

    public ArrayList<HashMap<String, String>> getResult() {
        SoapObject so, dicChild = null, dictionary, resultSo, transRes;
        String cityname, province, Nextprovince = null;
        so = new SoapObject(NAMESPACE, METHOD_NAME);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.bodyOut = so;
        envelope.dotNet = true;
        HttpTransportSE transport = new HttpTransportSE(serviceUrl);
        try {
            transport.call(SOAP_ACTION, envelope);
            resultSo = (SoapObject) envelope.bodyIn;
            // 上面为获得内容,下面为解析内容模块
            // 获得返回的结果
            transRes = (SoapObject) resultSo
                    .getProperty("getSupportProvinceCityResult");

            // 解析第二个属性
            dictionary = (SoapObject) transRes.getProperty(1);
            // 解析第二个属性的第一个节点内容
            dicChild = (SoapObject) dictionary.getProperty(0);

            int length = dicChild.getPropertyCount();

            for (int i = 0; i < length; i++) {
                province = Nextprovince;
                SoapObject sObject = (SoapObject) dicChild.getProperty(i);
                // 两种方法,分别获得省份和城市
                province = sObject.getProperty("PROVINCE").toString();
                cityname = sObject.getProperty(0).toString();
                Log.d("info", "cityname:" + cityname);
                // 将得到的数据添加到HashMap中,将HashMap设置到List里
                hm = new HashMap<String, String>();
                hm.put("province", province);
                hm.put("cityname", cityname);
                province_city.add(hm);
            }

        } catch (IOException e) {
            Log.e("TAG", "IO" + e.getMessage());
        } catch (XmlPullParserException e) {
            Log.e("TAG", "xml" + e.getMessage());
            e.printStackTrace();
        }
        return province_city;

    }

这是我自己写的代码,上面的代码我看不太懂!!!不好意思啊,这个是将得到的城市与省份设置到ListView里展示出来的。

请大家指点指点

mitty | 园豆:207 (菜鸟二级) | 2012-07-26 10:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册