JAVA+AXIS用戶端調用Asp.net Web Service過程中遇到的問題及解決方案

來源:互聯網
上載者:User

        背景:公司與某電訊廠商合作,電訊廠商提供了介面文檔,在文檔中規定了資料流是雙向的,電訊廠商和公司之間的通訊採用Web Service方式,雙方互為用戶端和伺服器端。這次遇到的問題,就是電訊廠商的用戶端調用我公司服務端的Web Service時出現的情況。需要特別說明的是:電訊廠商有幾十家夥伴,所以用戶端的代碼是不能因為某一家夥伴而修改的,各夥伴的WEB SERVICE開發環境也不相同,大部分都是用JAVA語言開發,而我公司是用VS2005開發的。
        過程:
        涉及的介面文檔部分如下:
使用者資料同步(syncUserData):

Index

Parameter Name

Req

Type

Size

Description

1

Mobile

M

String

21

使用者號碼

2

SPID

M

String

21

合作方標識

3

Service

M

String

21

業務代碼

4

Action

M

Integer

4

使用者操作

5

Time

M

String

14

時間戳記 YYYYMMDDhhmmss

6

Desc

M

String

255

原因描述

7

Terminal

M

String

4

終端類型


        電訊廠商用戶端採用:JAVA JDK 1.5+AXIS實現的Web Service用戶端調用,並提供了具體的調試例子:

package smp.webservice.client;

import java.rmi.RemoteException;

import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class ServiceClient ...{
    public int syncUserData(String Mobile, String SPID, String Service, Integer Action, String Time, String Desc,    String terminal, String serviceEndPoint)
        throws Exception ...{
        Object result=null;
        try ...{
            Call call = this.invokeFunction("syncUserData", serviceEndPoint);
            result=call.invoke(new Object[] ...{ Mobile, SPID, Service, Action, Time, Desc, terminal });
        } catch (Exception e) ...{
            throw e;
        }
        
        try...{
            return ((Integer)result).intValue();
        }catch(Exception e)...{
            return Integer.parseInt(((String)result));
        }
    }

    public Call invokeFunction(String operationName, String serviceEndPoint)
        throws ServiceException ...{
        Service service = ServiceInstance.getInstance();
        Call call = (Call) service.createCall();
        call.setTargetEndpointAddress(serviceEndPoint);
        call.setOperationName(new QName(operationName));
        return call;
    }

    /** *//**
     * test the client method
     */
    public static void main(String[] args) ...{
        ServiceClient sc = new ServiceClient();
        String endPoint = "http://127.0.0.1/WebTest/Service.asmx";

        try ...{
            int i=sc.syncUserData("13312345678", "3735127", "834621", new Integer(8), "20080101120000", "desc","9",endPoint);

            System.out.println("result: " + i);
        } catch (Exception e) ...{
            e.printStackTrace();
        }
    }
}

其中endPoint的值是用於調用我本地的.net開發的WEB服務地址。 
我用asp.net中的C#語言產生了WEB
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.