Solved

Soap request from Java from asp web service

Posted on 2008-06-24
6
1,268 Views
Last Modified: 2013-12-22
Hi expert, J have a problem with java & asp :
I want to call an as webservice from java app

but when j try i cath error,
Server returned HTTP response code: 405 for URL:.....
my web service is on
http://www.cma.hmade.biz/SyncWebService/HMSyncWebService.asmx
and the method that i want to call is dosyncfromzipfile

J think that the problem shoud be URL address or SoapAction
try

		{

			URL u = new URL("http://www.cma.hmade.biz/SyncWebService/");

			URLConnection uc = u.openConnection();

			HttpURLConnection httpCon = (HttpURLConnection)uc;

			httpCon.setDoOutput(true);

			httpCon.setDoInput(true);

			httpCon.setRequestMethod("POST");

			

			httpCon.setRequestProperty("Content-Type", "text/hml; charset=utf-8");

			httpCon.setRequestProperty("Content-Length", String.valueOf(382));

			httpCon.setRequestProperty("SOAPAction", "http://www.hmade.biz/doSyncFromZipFile");

			

			OutputStream out = httpCon.getOutputStream();

			Writer wout = new OutputStreamWriter(out);

			

		    wout.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");

		    wout.write("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");

		    wout.write("<soap:Body>");

		    wout.write("<doSyncFromZipFile xmlns=\"http://www.hmade.biz/\">");

		    wout.write("<updateXmlCmd>string</updateXmlCmd>");

		    wout.write("</doSyncFromZipFile>");

		    wout.write("</soap:Body>");

		    wout.write("</soap:Envelope>");

		    

			wout.flush();

			wout.close();

			

			InputStream in = httpCon.getInputStream();

			int c;

			while ((c=in.read())!=-1) System.out.write(c);

			in.close();

			

		}

		catch(Exception e)

		{

			System.err.println(e);

		}

Open in new window

0
Comment
Question by:hmade
  • 3
  • 3
6 Comments
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 21855216
may i know why you are using this approach of posting a XML directly to the Web service ? instead  you might have used the HTTP POST style mentioned at

http://www.cma.hmade.biz/SyncWebService/HMSyncWebService.asmx?op=doSyncFromZipFile

your SOAP msg looks appropriate but b7y http 405 what we can under stand is that your web server is not accepting your POST request. I feel this is wrong

  URL u = new URL("http://www.cma.hmade.biz/SyncWebService/");

in the sense the above URL doesn't accept a post url,  infact if you are posting via direct HTTP request I suggest to go with the HTTP POST approach mentioned in the first link .
POST /SyncWebService/HMSyncWebService.asmx/doSyncFromZipFile HTTP/1.1

Host: www.cma.hmade.biz

Content-Type: application/x-www-form-urlencoded

Content-Length: length
 

updateXmlCmd=string

Open in new window

0
 

Author Comment

by:hmade
ID: 21855722
Thank's guru, the problemi is that my string param is a xml string and so i don't know if HTTP POST approach is the right way
0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 21855898
it will not matter if its a XML or a normal string it will be considered as a plain text only, better try with HTTP POST approach.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:hmade
ID: 21856098
can you send me a sample for this solution?
0
 
LVL 23

Accepted Solution

by:
Siva Prasanna Kumar earned 300 total points
ID: 21861677
I think this question should have been 500 points ;) Just kidding here is your solution
import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import java.io.OutputStreamWriter;

import java.io.Writer;

import java.net.HttpURLConnection;

import java.net.URL;

import java.net.URLConnection;
 
 

public class TestHttpClient {

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

	  URL u = new URL("http://www.cma.hmade.biz/SyncWebService/HMSyncWebService.asmx/doSyncFromZipFile");

      URLConnection uc = u.openConnection();

      HttpURLConnection httpCon = (HttpURLConnection)uc;

      httpCon.setDoOutput(true);

      httpCon.setDoInput(true);

      httpCon.setRequestMethod("POST");

      String data="<abc>aaaa</abc>";

      httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

      httpCon.setRequestProperty("Content-Length", String.valueOf(data.length()));

      httpCon.setRequestProperty("Host", "www.cma.hmade.biz");

      OutputStream out = httpCon.getOutputStream();

      Writer wout = new OutputStreamWriter(out);

      wout.write("updateXmlCmd="+data);

      wout.flush();

      wout.close();

      

      InputStream in = httpCon.getInputStream();

      byte[] response = new byte[httpCon.getContentLength()];

      

      in.read(response);

      

      System.out.println(new String(response));

      

}

}

Open in new window

0
 

Author Comment

by:hmade
ID: 21863089
Excellent!!!
That is exactly what i'm looking for...
thanks a lot
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now