webservice系列教学(4)-如何调用webservice(pb,java)

<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
4.1 使用PowerBuilder调用
    适用版本8.0 需下载Bulletin Web Services Toolkit 4.1
4.2使用java调用
需要下载apache soap。下载地址:http://xml.apache.org/soap/index.html
导入:
import org.apache.soap.*;
import org.apache.soap.rpc.*;
例程:
import java.io.*;
import java.util.*;
import java.net.*;
import org.w3c.dom.*;
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.encoding.*;
import org.apache.soap.encoding.soapenc.*;
import org.apache.soap.rpc.*;
import org.apache.soap.transport.http.SOAPHTTPConnection;

public class testClient {

    public static void main(String[] args) throws Exception {

        URL url = new URL ("http://192.168.0.4/yundan/service1.wsdl");
//改成你的地址
        SOAPMappingRegistry smr = new SOAPMappingRegistry ();
        StringDeserializer sd = new StringDeserializer ();
        smr.mapTypes (Constants.NS_URI_SOAP_ENC, new QName ("", "Result"), null, null, sd);

        // 创建传输路径和参数
        SOAPHTTPConnection st = new SOAPHTTPConnection();

        // 创建调用
        Call call = new Call ();
        call.setSOAPTransport(st);
        call.setSOAPMappingRegistry (smr);

        call.setTargetObjectURI ("http://tempuri.org/message/");
        call.setMethodName("addNumbers");
        call.setEncodingStyleURI ("http://schemas.xmlsoap.org/soap/encoding/");

        Vector params = new Vector();
        params.addElement(new Parameter("NumberOne", Double.class, "10", null));
        params.addElement(new Parameter("NumberTwo", Double.class, "25", null));
        call.setParams(params);

        Response resp = null;

        try {
          resp = call.invoke (url, "http://tempuri.org/action/Hello2.addNumbers");
        }
        catch (SOAPException e) {
        System.err.println("Caught SOAPException (" + e.getFaultCode () + "): " + e.getMessage ());
        return;
        }

        // 检查返回值
        if (resp != null && !resp.generatedFault()) {
        Parameter ret = resp.getReturnValue();
        Object value = ret.getValue();

        System.out.println ("Answer--> " + value);
        }
        else {
            Fault fault = resp.getFault ();
            System.err.println ("Generated fault: ");
            System.out.println (" Fault Code = " + fault.getFaultCode());
            System.out.println (" Fault String = " + fault.getFaultString());
        }
    }
}

11AIF6353091J0.jpg
seover="window.status='正文--webservice系列教学(4)-如何调用webservice(pb,java)';return true">
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
阅读更多
个人分类: .net
想对作者说点什么? 我来说一句

PB调用JAVA WEBSERVICE实例

2013年09月13日 2.24MB 下载

pb12.5调用java WebService

2013年08月21日 179KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭