I am developing a web service to allow uploading from client to server. I was able to get wsdl file at http://localhost:9999/UploadWebservice?wsdl
. Here is its content
<?xml version="1.0" encoding="UTF-8"?>
<!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. -->
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. -->
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws/" name="ImageServerImplService">
<types></types>
<message name="upload">
<part name="arg0" type="xsd:string"></part>
<part name="arg1" type="xsd:base64Binary"></part>
</message>
<message name="uploadResponse">
<part name="return" type="xsd:string"></part>
</message>
<portType name="ImageServer">
<operation name="upload" parameterOrder="arg0 arg1">
<input message="tns:upload"></input>
<output message="tns:uploadResponse"></output>
</operation>
</portType>
<binding name="ImageServerImplPortBinding" type="tns:ImageServer">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"></soap:binding>
<operation name="upload">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal" namespace="http://ws/"></soap:body>
</input>
<output>
<soap:body use="literal" namespace="http://ws/"></soap:body>
</output>
</operation>
</binding>
<service name="ImageServerImplService">
<port name="ImageServerImplPort" binding="tns:ImageServerImplPortBinding">
<soap:address location="http://localhost:9999/UploadWebservice"></soap:address>
</port>
</service>
</definitions>
Now I am writing a client to consume the service. Here is the client
package ws;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Map;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.soap.SOAPBinding;
import com.sun.xml.ws.developer.JAXWSProperties;
public class ClientTaiwan {
public static void main(String[] args) {
ImageServerImplService service = new ImageServerImplService();
ImageServer delegate = service.getImageServerImplPort();
// Enable MTOM
BindingProvider bp = (BindingProvider) delegate;
SOAPBinding binding = (SOAPBinding) bp.getBinding();
binding.setMTOMEnabled(true);
// Set chunk size
Map<String, Object> ctxt =
((BindingProvider)delegate).getRequestContext();
ctxt.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192);
byte[] b;
try {
RandomAccessFile f = new RandomAccessFile("c:\\100MB.zip", "r");
b = new byte[(int) f.length()];
f.read(b);
f.close();
delegate.upload("c://Upload//100MB.zip", b);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Done!");
}
}
I receive the following stack trace
Exception in thread "main" javax.xml.ws.WebServiceException: java.io.IOException: Error writing request body to server
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:225)
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:136)
at com.sun.xml.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:110)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1063)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:979)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:950)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:825)
at com.sun.xml.ws.client.Stub.process(Stub.java:443)
at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:174)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:119)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:102)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:154)
at com.sun.proxy.$Proxy33.upload(Unknown Source)
at ws.ClientTaiwan.main(ClientTaiwan.java:47)
Caused by: java.io.IOException: Error writing request body to server
at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.checkError(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.write(Unknown Source)
at com.sun.xml.ws.transport.http.client.HttpClientTransport$WSChunkedOuputStream.write(HttpClientTransport.java:365)
at javax.activation.DataHandler.writeTo(Unknown Source)
at com.sun.xml.ws.encoding.MtomCodec$ByteArrayBuffer.write(MtomCodec.java:229)
at com.sun.xml.ws.encoding.MtomCodec.encode(MtomCodec.java:185)
at com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:242)
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:214)
The line that causes the problem is delegate.upload("c://Upload//100MB.zip", b);
Why does a published service is still not visible for its client? How can I fix it? If you have any concern about my coding style please let me know. Things are a little out of my control right now.
Best regards