java– 通过Web服务从服务器向客户端发送pdf文件

java– 通过Web服务从服务器向客户端发送pdf文件,第1张

概述由于我是网络服务新手,请您回答我的问题.我的问题是Iwanttoimplementawebservicewhichsendspdffilestoclientastheclientcallsthiswebservice.请有人帮我处理好的代码或解释.现在可以请一些人解决我的错误.12-2309:42:48.429:DEBUG/installd(32):D

由于我是网络服务新手,请您回答我的问题.
我的问题是

I want to implement a web service which sends pdf files to clIEnt as the clIEnt calls this web service.

请有人帮我处理好的代码或解释.

现在可以请一些人解决我的错误.

12-23 09:42:48.429: DEBUG/installd(32): DexInv: — BEGIN ‘/data/app/vmdl33143.tmp’ —
12-23 09:42:51.708: DEBUG/dalvikvm(328): DexOpt: ‘Lorg/xmlpull/v1/XmlPullParser;’ has an earlIEr deFinition; blocking out
12-23 09:42:51.730: DEBUG/dalvikvm(328): DexOpt: ‘Lorg/kxml2/io/KXmlParser;’ has an earlIEr deFinition; blocking out
12-23 09:42:51.749: DEBUG/dalvikvm(328): DexOpt: ‘Lorg/xmlpull/v1/XmlSerializer;’ has an earlIEr deFinition; blocking out
12-23 09:42:51.759: DEBUG/dalvikvm(328): DexOpt: ‘Lorg/kxml2/io/KXmlSerializer;’ has an earlIEr deFinition; blocking out
12-23 09:42:51.779: DEBUG/dalvikvm(328): DexOpt: ‘Lorg/kxml2/kdom/Node;’ has an earlIEr deFinition; blocking out
12-23 09:42:51.779: DEBUG/dalvikvm(328): DexOpt: ‘Lorg/kxml2/kdom/document;’ has an earlIEr deFinition; blocking out
12-23 09:42:51.819: DEBUG/dalvikvm(328): DexOpt: ‘Lorg/kxml2/kdom/Element;’ has an earlIEr deFinition; blocking out
12-23 09:42:51.830: DEBUG/dalvikvm(328): DexOpt: ‘Lorg/kxml2/wap/Wbxml;’ has an earlIEr deFinition; blocking out
12-23 09:42:51.840: DEBUG/dalvikvm(328): DexOpt: ‘Lorg/kxml2/wap/WbxmlParser;’ has an earlIEr deFinition; blocking out
12-23 09:42:51.900: DEBUG/dalvikvm(328): DexOpt: ‘Lorg/kxml2/wap/WbxmlSerializer;’ has an earlIEr deFinition; blocking out
12-23 09:42:51.910: DEBUG/dalvikvm(328): DexOpt: ‘Lorg/kxml2/wap/syncml/SyncML;’ has an earlIEr deFinition; blocking out
12-23 09:42:51.910: DEBUG/dalvikvm(328): DexOpt: ‘Lorg/kxml2/wap/wml/Wml;’ has an earlIEr deFinition; blocking out
12-23 09:42:51.929: DEBUG/dalvikvm(328): DexOpt: ‘Lorg/kxml2/wap/wv/WV;’ has an earlIEr deFinition; blocking out
12-23 09:42:51.929: DEBUG/dalvikvm(328): DexOpt: ‘Lorg/xmlpull/v1/XmlPullParserException;’ has an earlIEr deFinition; blocking out
12-23 09:42:51.949: DEBUG/dalvikvm(328): DexOpt: ‘Lorg/xmlpull/v1/XmlPullParserFactory;’ has an earlIEr deFinition; blocking out
12-23 09:42:53.299: INFO/dalvikvm(328): DexOpt: not resolving ambiguous class ‘Lorg/xmlpull/v1/XmlPullParser;’
12-23 09:42:53.319: INFO/dalvikvm(328): DexOpt: not resolving ambiguous class ‘Lorg/xmlpull/v1/XmlPullParser;’
12-23 09:42:53.329: INFO/dalvikvm(328): DexOpt: not resolving ambiguous class ‘Lorg/xmlpull/v1/XmlPullParser;’
12-23 09:42:53.350: INFO/dalvikvm(328): DexOpt: not resolving ambiguous class ‘Lorg/xmlpull/v1/XmlPullParser;’
12-23 09:42:53.350: INFO/dalvikvm(328): DexOpt: not resolving ambiguous class ‘Lorg/xmlpull/v1/XmlPullParser;’
12-23 09:42:53.370: INFO/dalvikvm(328): DexOpt: not resolving ambiguous class ‘Lorg/xmlpull/v1/XmlPullParser;’
12-23 09:42:53.499: INFO/dalvikvm(328): DexOpt: not resolving ambiguous class ‘Lorg/xmlpull/v1/XmlPullParser;’
12-23 09:42:53.560: INFO/dalvikvm(328): DexOpt: not resolving ambiguous class ‘Lorg/xmlpull/v1/XmlPullParser;’
12-23 09:42:53.570: INFO/dalvikvm(328): DexOpt: not resolving ambiguous class ‘Lorg/kxml2/io/KXmlSerializer;’
12-23 09:42:53.659: DEBUG/dalvikvm(328): DexOpt: not verifying ‘Lorg/xmlpull/v1/XmlPullParser;’: multiple deFinitions
12-23 09:42:53.668: DEBUG/dalvikvm(328): DexOpt: not verifying ‘Lorg/kxml2/io/KXmlParser;’: multiple deFinitions
12-23 09:42:53.668: DEBUG/dalvikvm(328): DexOpt: not verifying ‘Lorg/xmlpull/v1/XmlSerializer;’: multiple deFinitions
12-23 09:42:53.668: DEBUG/dalvikvm(328): DexOpt: not verifying ‘Lorg/kxml2/io/KXmlSerializer;’: multiple deFinitions
12-23 09:42:53.680: DEBUG/dalvikvm(328): DexOpt: not verifying ‘Lorg/kxml2/kdom/Node;’: multiple deFinitions
12-23 09:42:53.690: DEBUG/dalvikvm(328): DexOpt: not verifying ‘Lorg/kxml2/kdom/document;’: multiple deFinitions
12-23 09:42:53.709: DEBUG/dalvikvm(328): DexOpt: not verifying ‘Lorg/kxml2/kdom/Element;’: multiple deFinitions
12-23 09:42:53.709: DEBUG/dalvikvm(328): DexOpt: not verifying ‘Lorg/kxml2/wap/Wbxml;’: multiple deFinitions
12-23 09:42:53.719: DEBUG/dalvikvm(328): DexOpt: not verifying ‘Lorg/kxml2/wap/WbxmlParser;’: multiple deFinitions
12-23 09:42:53.719: DEBUG/dalvikvm(328): DexOpt: not verifying ‘Lorg/kxml2/wap/WbxmlSerializer;’: multiple deFinitions
12-23 09:42:53.719: DEBUG/dalvikvm(328): DexOpt: not verifying ‘Lorg/kxml2/wap/syncml/SyncML;’: multiple deFinitions
12-23 09:42:53.719: DEBUG/dalvikvm(328): DexOpt: not verifying ‘Lorg/kxml2/wap/wml/Wml;’: multiple deFinitions
12-23 09:42:53.719: DEBUG/dalvikvm(328): DexOpt: not verifying ‘Lorg/kxml2/wap/wv/WV;’: multiple deFinitions
12-23 09:42:53.719: DEBUG/dalvikvm(328): DexOpt: not verifying ‘Lorg/xmlpull/v1/XmlPullParserException;’: multiple deFinitions
12-23 09:42:53.719: DEBUG/dalvikvm(328): DexOpt: not verifying ‘Lorg/xmlpull/v1/XmlPullParserFactory;’: multiple deFinitions
12-23 09:42:53.829: DEBUG/dalvikvm(328): DexOpt: load 867ms, verify 1752ms, opt 108ms
12-23 09:42:54.029: DEBUG/installd(32): DexInv: — END ‘/data/app/vmdl33143.tmp'(success) —

这是android模拟器的DDMS中的错误.

现在我的网络服务&代码看起来像这样.

码:-

package com.uks.webservice;import java.io.fileNotFoundException;  import java.io.IOException;  import java.rmi.Remote;  public interface Sendpdf extends Remote {    public String[] sendpdf() throws fileNotFoundException, IOException,            Exception;}

创建Web服务的主类: –

package com.uks.webservice;import java.io.file;   import java.io.fileNotFoundException;  import java.io.IOException;  import java.io.inputStream;  import javax.activation.DataHandler;  import javax.activation.fileDataSource;  import sun.misc.BASE64Encoder;  public class SendpdfImpl implements Sendpdf {@OverrIDepublic String[] sendpdf() {    String[] pdffile = new String[2];    BASE64Encoder encoder = new BASE64Encoder();    file file = new file(            "C:/eclipse/workspace/AipwebService/src/test.pdf");    DataHandler dh = new DataHandler(new fileDataSource(file));    String readline = null;    byte[] data = new byte[(int) file.length()];    int offset = 0;    int numRead = 0;    inputStream stream = null;    try {        System.out.println("Web Service Called Successfully");        stream = dh.getinputStream();        // BufferedReader bufferedReader = new BufferedReader(        // new inputStreamReader(stream));        while (offset < data.length                && (numRead = stream.read(data, offset, data.length                        - offset)) >= 0) {            offset += numRead;        }        readline = encoder.encode(data);        // while ((readline = bufferedReader.readline()) != null) {        System.out.println("'Reading file............................");        System.out.println("\n");        System.out.println("Data Reading Successful");        pdffile[0] = file.getname();        pdffile[1] = readline;        stream.close();    } catch (fileNotFoundException e) {        e.printstacktrace();    } catch (IOException e) {        e.printstacktrace();    } catch (Exception e) {        e.printstacktrace();    }    return pdffile;}}

网络服务:-

<?xml version="1.0" enCoding="UTF-8"?><wsdl:deFinitions targetnamespace="http://webservice.uks.com"    xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://webservice.uks.com"    xmlns:intf="http://webservice.uks.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"    xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">    <!--        WSDL created by Apache Axis version: 1.4 Built on Apr 22, 2006        (06:55:48 PDT)    -->    <wsdl:types>        <schema elementFormDefault="qualifIEd" targetnamespace="http://webservice.uks.com"            xmlns="http://www.w3.org/2001/XMLSchema">            <element name="sendpdf">                <complexType />            </element>            <element name="sendpdfResponse">                <complexType>                    <sequence>                        <element maxOccurs="unbounded" name="sendpdfReturn" type="xsd:String" />                    </sequence>                </complexType>            </element>        </schema>    </wsdl:types>    <wsdl:message name="sendpdfRequest">        <wsdl:part element="impl:sendpdf" name="parameters" />    </wsdl:message>    <wsdl:message name="sendpdfResponse">        <wsdl:part element="impl:sendpdfResponse" name="parameters" />    </wsdl:message>    <wsdl:portType name="SendpdfImpl">        <wsdl:operation name="sendpdf">            <wsdl:input message="impl:sendpdfRequest" name="sendpdfRequest" />            <wsdl:output message="impl:sendpdfResponse" name="sendpdfResponse" />        </wsdl:operation>    </wsdl:portType>    <wsdl:binding name="SendpdfImplSoapBinding" type="impl:SendpdfImpl">        <wsdlsoap:binding             transport="http://schemas.xmlsoap.org/soap/http" />        <wsdl:operation name="sendpdf">            <wsdlsoap:operation soapAction="" />            <wsdl:input name="sendpdfRequest">                <wsdlsoap:body use="literal" />            </wsdl:input>            <wsdl:output name="sendpdfResponse">                <wsdlsoap:body use="literal" />            </wsdl:output>        </wsdl:operation>    </wsdl:binding>    <wsdl:service name="SendpdfImplService">        <wsdl:port binding="impl:SendpdfImplSoapBinding" name="SendpdfImpl">            <wsdlsoap:address                location="http://localhost:8080/AipwebService/services/SendpdfImpl" />        </wsdl:port>    </wsdl:service></wsdl:deFinitions>

现在我的AndroID代码.

package com.uks.androID.webservice;import androID.app.Activity;  import androID.os.Bundle;  import androID.Widget.TextVIEw;  import org.ksoap2.soapEnvelope;  import org.ksoap2.serialization.soapObject;  import org.ksoap2.serialization.soapSerializationEnvelope;  import org.ksoap2.transport.AndroIDhttpTransport;  public class pdfActivity extends Activity {      private final String METHOD_name = "sendpdf";      private final String nameSPACE = "http://webservice.uks.com/";      private final String SOAP_ACTION = nameSPACE + METHOD_name;      private final String URL = "http://192.168.1.123:8080/AipwebService/services/SendpdfImpl";      /** Called when the activity is first created. */    @OverrIDe    public voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.main);        TextVIEw textVIEwOne = (TextVIEw) findVIEwByID(R.ID.textVIEwOne);        TextVIEw textVIEwTwo = (TextVIEw) findVIEwByID(R.ID.textVIEwTwo);        try {            SoapObject soapObject = new SoapObject(nameSPACE, METHOD_name);            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(                    SoapEnvelope.VER11);            envelope.setoutputSoapObject(soapObject);            textVIEwOne.setText("Web Service Started");            AndroIDhttpTransport httpTransport = new AndroIDhttpTransport(URL);            httpTransport.call(SOAP_ACTION, envelope);            SoapObject result = (SoapObject) envelope.getResponse();            textVIEwTwo.setText(result.toString());            // Object result = envelope.getResponse();            // fileOutputStream outputStream = openfileOutput(name, mode)        } catch (Exception e) {            e.printstacktrace();        }    }}

请帮我.

提前致谢.

解决方法:

您需要将文件转换为字节数组并将其传递给服务器上的服务执行相反的 *** 作以获取文件.

> Here is very good article on doing this using JAXWS

总结

以上是内存溢出为你收集整理的java – 通过Web服务从服务器向客户端发送pdf文件全部内容,希望文章能够帮你解决java – 通过Web服务从服务器向客户端发送pdf文件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1098568.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存