Sending SOAP attachments from Axis client to .NET web service

Hi all,

I have an Apache Axis client that sends an attachment using javax.activation.DataHadler class. The web service is to be built in VB .NET and it will do a conversion to PDF and back the attachment to the client. My question is fairly simple:

How can a .NET web service handle the attachment being sent to it as a DataHandler object from a java client? Can this be done? if not then how can i send an attachment from java client(axis) to a .NET web service? base64 encoding is not an option.

This is my client side code:

 public boolean transform(final boolean doTheDIME, String fileName) throws Exception {

      byte[] buffer = null;
      String fileNameToSave = null;
      timeStamp = System.currentTimeMillis();
      fileNameToSave = StripPath(fileName);
      int index = fileNameToSave.indexOf(".");
      if ( index >= 0 )
       fileNameToSave = fileNameToSave.substring(0, index);//note this would include the full path + filename
         //javax.activation.MimetypesFileTypeMap map= (javax.activation.MimetypesFileTypeMap)javax.activation.MimetypesFileTypeMap.getDefaultFileTypeMap();
         //map.addMimeTypes("application/x-org-apache-axis-wsdd wsdd");

      System.out.println("Inside transform...");
         //Create the data for the attached file.
      File f = new File(fileName);
      buffer = getBytesFromFile(f);
       //  DataHandler dhSource = new DataHandler(new FileDataSource(fileName));
         DataHandler dhSource = new DataHandler(new ByteArrayDataSource(buffer, "application/octet-stream"));
      Service service = new Service();

         Call call = (Call) service.createCall();

         call.setTargetEndpointAddress(new URL(opts.getURL())); //Set the target service host

//This is the target services method to invoke.and service location,

         call.setOperationName(new QName("MyService", "TransformFile"));

         QName qnameAttachment = new QName("MyService", "DataHandler");

           /**Add serializer for attachment**/

         call.addParameter("source", qnameAttachment, ParameterMode.IN); //Add the file.
         call.addParameter("fileName", XMLType.XSD_STRING, ParameterMode.IN); //Add the file name.



         System.err.println("Received \""+dhSource.getClass().getName()+"\".");
         System.err.println("Received \""+dhSource.getClass().getName()+"\".");
         System.err.println("Content Type: "+dhSource.getContentType());
         System.err.println("Name: "+dhSource.getName());
         System.err.println("Content: "+dhSource.getContent ());
         QName qNameOut = new QName("","List");
         if (doTheDIME)
         long start = new Date().getTime();
            ///invoke the web services method and receive the response
         Object ret = call.invoke( new Object[]{ dhSource, fileName });

//Add the attachment.
         List ret = (List)call.invoke(new Object[]{ dhSource, fileName});
            long end = new Date().getTime();
            long time = end - start;
            System.out.println("Conversion Time: " + time);
         System.out.println("RESPONSE MESSAGE:");

   //get the soap message being received
         MessageContext msg = call.getMessageContext();
         if (null == ret) {
             System.out.println("Received null ");
             throw new AxisFault("", "Received null", null, null);

               //in case return object was a java.util.list
        org.apache.axis.attachments.AttachmentPart a =  (org.apache.axis.attachments.AttachmentPart)ret.get(0);
        DataHandler rdh = a.getDataHandler(); 
       fileNameToSave = (String)ret.get(1);
         String receivedfileName = rdh.getName();//Get the filename. 
     String destFileName = createOutputFileName(fileNameToSave + timeStamp + ".pdf");
     String destFileName = createOutputFileName(fileNameToSave);
         //write the file we received from the web service  
      writeFileToLocalMachine(rdh, destFileName);
         return true;



Thanks in advance...Big Smile [:D]


2/7/2006 5:56:15 PM 7071 articles. 0 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 31

Pretty brave, looking for Java expertise over here Stick out tongue [:P]

Actually the DataHandler is not your biggest problem.  Each Serializer has a writeSchema method, use this to get a schema for your DataHandler.  Feed this schema to XSD.exe and you should have some .NET types you can use in your .NET web service.

The real challenge is that you seem to be expecting the web service to return a Java list s this line shows:

List ret = (List)call.invoke(new Object[]{ dhSource, fileName});

That's the real challenge, you're not going to get that right.  Stick to arrays and then convert to a list in the Java client.



My Blog:
2/9/2006 8:05:34 PM

Forgot to mention, you'll have to use WSE at the .NET end, which supports both DIME and MIME attachments, as ASMX web services only support basic SOAP.


My Blog:
2/9/2006 8:29:35 PM

Similar Artilces:

How to call a .net web service from another .net web service?
Hi all,I have developed two asp .net web services using visual studio .net 2003.I wish to call one web service from another web service.I tried adding a web reference of the web service in another web service and was able to do so.but i m not able to access the web methods provided by the web servicecould you please suggest a way to go about itExpecting quick replyThanxCharmy try to make sure that you reference it in the web reference and call it properly this is sample  [WebMethod()] public double CalcDistance(int x1, int y1, int x2, int y2) { Calculator.Service1 calc = new...

Web service in .NET from Java Web Service
Hi there,I'm pretty new to .net (although i have years of experience with the old vb 6, access 2k, as well as java)... and need some with perhaps either some syntax or something.Here is the wsdl.<wsdl:definitions targetNamespace="">−<wsdl:types>−<schema targetNamespace="GetBookInfoByISBN">−<complexType name="BookInfoType">−<sequence><element maxOccurs="1" minOccurs="0" name="Title" nillable="true" type="xsd:string"/><element maxOccurs=&quo...

.NET web services Vs Java Web Services
Hello, does anyone know of a book or good source of information that compares .NET and Java Web Services? (I would like soemthing neutral if possible). I am thinking of approaching this subject for my dissertation? Many Thanks Rob Hi Rob, Last year I had to give a powepoint presentation on Web Services. I noticed some good books at barnes and noble that discussed the subject. These books were specific to Java and discussed Web Services in a very clear fashion. They gave some elementary examples that were easy to understand. I have not yet had the pleasure of creatin .NET Web Servi...

I develop in .net and need to create a web client to connect to a web service built in Java. Its pretty easy when the web service was also built in .net. You can just create a web reference with the gui and automatically can see its functions and stuff. when i put this url in the box and hit go i dont get to see its functions. maybe this shouldnt be the url of the WSDL?? I Have no idea. Im very new to all of this. If there are any examples of .net clients connecting to non .net web clients it woul...

Can you return .net web controls in a .net page from a web service?
I've got a problem with a project. I've got to compile an entire .net page and return it as part of a Web Service for display. The problem I have is that I need to add WebControls and functionality to the page so that not only the html content and images are displayed (which I've managed) but that textboxes, labels, buttons and datasets can be displayed also. Essentially I need to make a call from one site for a page, populate the page and return it in a state as though it resided on the same server/webspace as the calling page. Code is currently built as follows into a string: strOpenHT...

xml web service --uploading the file to the xml web service
how can we upload the file in the xml web service 1.i mean what will be the return value in the proxy class 2.and how am i going to send the file to the xml web service----regards Bipul Kumar Here are some links to articles that helped us get this done: Hope this helps....

create valid xml to send to web service based on the schema provided by web service
Problem: I have a web page which is being populated from a dataset containing multiple tables.  I now need to call a web service and send the majority of this data to be incorporate into a mainframe system.  I have been supplied with the schema that the web service will be using to validate the data.  I am new to web services and I am not sure how to take my existing dataset and transform it into an xml document that matches the schema I was provided with. There is a main schema with an element which is a custom complex type.  This custom type consists of an element whi...

Best Practice for .Net Web Service access to a Web Service on a Test and Production Servers
Hello All, What is the best way to control a .Net web service to be able to access a remote server for testing and then point to another remote server to access the web service in production? Do I need to generate and maintain 2 different proxy objects? TIA, Bob Bob // first create the proxy if not isvalid( i_service) then i_service = create fundtraderproxy_TradeServicesClient_BasicHttpBinding_ITradeServices end if ///You'll see code something like this in the constructor of your proxy //dynamically set the endpoint url with the user supplied value - //r...

WS-Security with VS.NET 2005 Web Service and .NET 1.1 Client
We ship a webservices client piece into the field which is required to run on the .NET 1.1 version of the framework, this is defined by our business people and cannot change. We would like to work with .NET 2.0 in VS.NET 2005 for the backend Web Service piece. We are able to get the 2 to communicate fine and it is not a problem. The issue now is that we need to introduce security through WS-Security. I have not been able to find much information about interop between the 2 environments and WS-Security and cannot get the security elements to be invoked in VS.NET 2005. Currently we are trying ...

Web Service apache axis array problem in .net client
I am trying to use a Web Service generated on Apache Axis and complex types(arrays) only get empty array. I am testing: getFuelTypes My code VS2005 VB: Dim Service As TecdocToCatSkeletonService = New TecdocToCatSkeletonService Dim aa As FuelTypesRequest = New FuelTypesRequest     aa.provider = 147    aa.lang = "pt" Dim ftypes As FuelTypesResponse = New FuelTypesResponse()     ftypes = Service.getFuelTypes(aa) I made a proxy with wsdl.exe and change the proxy to...

XML Web Service Message from .NET to NonStop SOAP Server
Here's the XML parsing error the NonStop (Tandem) SOAP Server is generating as a result of a Web Service request from my .NET web client.  The web service in question works fine when the XML request comes from the "test" html client.  My question is, is this a lack of carriage returns a problem?  (see trace information below) >> 2008/10/15 14:32:3::Y7H3:<< Unmarshal Error: Invalid input document: Unexpected extra node(s) at the end of the document>> 2008/10/15 14:32:3::Y7H3:<< SoapDocumentHandler::process:Fault occurre...

Troubleshoot Web Service; Ajax AutoComplete events do not appear to not fire; Ajax web service appears to not work. .NET
Folks, I had the situation that Ajax AutoComplete events in the web service did not fire after I copied a project out of a folder, renamed it and moved it to a server. The fix was hard to find but easy to solve. I had some web service modules in an ASMX file that provided AutoComplete entries -- i.e., after the user keys in 2 or 3 characters, the list of possible entries with those leading characters is displayed for the user to select. To solve the problem, look at the web service's directive, not the code-behind or the ASMX designer.  Do a right-mouse-click...

Issue with clients consuming a web service that was upgraded from .NET 1.1 to .NET 3.5
I am currently working with an application that was converted from Visual Studio 2003 to Visual Studio 2008 and we are having issues with a client consuming the web service portion of the application.  The web services were written in .NET 1.1 using the Web Services Enhancements 2.0 and was upgraded to use the .NET 3.5 framework.  One of our clients application, which is still written in .NET 1.1 was reference the upgraded web service and tried to consume the web service and received the following error: System.Web.Services.Protocols.SoapException: Se...

.NET Web Service and Non .NET programe
When we develop a web service by VB.NET. Then i use visual basic, Microsoft access, asp. Can these stuff access to my web service ? Means you want to access Webserver developed in VB.NET in ASP application?Sreedharhttp://www.w3coder.orgweblog