티스토리 뷰
Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
How to call a SOAP web service on Android
안드로이드에서 SOAP(Simple Object Access Protocol) 웹 서비스를 호출하는 방법
문제 내용
I am having a lot of trouble finding good information on how to call a standard SOAP/WSDL web service with Android. All I've been able to find are either very convoluted documents and references to "kSoap2" and then some bit about parsing it all manually with SAX. OK, that's fine, but it's 2008, so I figured there should be some good library for calling standard web services.
Android에서 표준 SOAP/WSDL 웹 서비스를 호출하는 방법을 찾는 것이 어려운데, 찾은 자료는 대부분 복잡하고 "kSoap2"와 같은 참조 및 SAX를 사용하여 수동으로 모두 구문 분석해야한다는 내용이었습니다. 그렇다면 좋은 라이브러리가 있을 것이라고 생각했지만, 찾지 못했습니다. 이것이 2008년인데도 그렇습니다.
The web service is just basically one created in NetBeans. I would like to have IDE support for generating the plumbing classes. I just need the easiest/most-elegant way to contact a WSDL based web service from an Android-based phone.
이 웹 서비스는 NetBeans에서 생성된 것입니다. 나는 IDE 지원으로 수도관 클래스를 생성하고 싶습니다. 안드로이드 기반의 폰에서 WSDL 기반 웹 서비스에 가장 간단하고 우아한 방법만 필요합니다.
높은 점수를 받은 Solution
Android does not provide any sort of SOAP library. You can either write your own, or use something like kSOAP 2. As you note, others have been able to compile and use kSOAP2 in their own projects, but I haven't had to.
안드로이드는 SOAP 라이브러리를 제공하지 않습니다. 직접 작성하거나 kSOAP 2와 같은 것을 사용할 수 있습니다. 다른 사람들은 kSOAP2를 컴파일하고 자신의 프로젝트에서 사용할 수 있었다고 말하고 있지만, 나는 그렇게 하지 않아도 되었습니다.
Google has shown, to date, little interest in adding a SOAP library to Android. My suspicion for this is that they'd rather support the current trends in Web Services toward REST-based services, and using JSON as a data encapsulation format. Or, using XMPP for messaging. But that is just conjecture.
현재까지 구글은 안드로이드에 SOAP 라이브러리를 추가하는 데에 별 관심이 없는 것으로 보입니다. 제 생각으로는, 구글은 현재 웹 서비스의 트렌드인 REST 기반 서비스 및 데이터 캡슐화 형식으로 JSON을 사용하는 것을 지원하려는 것으로 추정됩니다. 또는 메시징에 XMPP를 사용하는 것입니다. 하지만 이것은 추측에 불과합니다.
XML-based web services are a slightly non-trivial task on Android at this time. Not knowing NetBeans, I can't speak to the tools available there, but I agree that a better library should be available. It is possible that the XmlPullParser will save you from using SAX, but I don't know much about that.
현재 안드로이드에서 XML 기반 웹 서비스 호출은 약간 복잡한 작업입니다. NetBeans를 모르기 때문에 해당 도구에 대해 언급할 수는 없지만, 더 나은 라이브러리가 제공되어야 한다는 것에 동의합니다. XmlPullParser를 사용하면 SAX를 사용하지 않아도 되므로 이것이 문제를 해결할 수도 있습니다.
가장 최근 달린 Solution
You may perform soap call as post over http with certain headers. I solved this question without additional libraries like ksoap2 Here is live code getting orders from soap service
일부 헤더와 함께 HTTP를 통해 SOAP 호출을 수행할 수 있습니다. 저는 ksoap2와 같은 추가 라이브러리 없이 이 문제를 해결했습니다. 다음은 SOAP 서비스에서 주문을 가져오는 라이브 코드입니다.
private static HashMap<String,String> mHeaders = new HashMap<>();
static {
mHeaders.put("Accept-Encoding","gzip,deflate");
mHeaders.put("Content-Type", "application/soap+xml");
mHeaders.put("Host", "35.15.85.55:8080");
mHeaders.put("Connection", "Keep-Alive");
mHeaders.put("User-Agent","AndroidApp");
mHeaders.put("Authorization","Basic Q2xpZW50NTkzMzppMjR3s2U="); // optional
}public final static InputStream receiveCurrentShipments(String stringUrlShipments)
{
int status=0;
String xmlstring= "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:ser=\"http://35.15.85.55:8080/ServiceTransfer\">\n" +
" <soap:Header/>\n" +
" <soap:Body>\n" +
" <ser:GetAllOrdersOfShipment>\n" +
" <ser:CodeOfBranch></ser:CodeOfBranch>\n" +
" </ser:GetAllOrdersOfShipment>\n" +
" </soap:Body>\n" +
"</soap:Envelope>";
StringBuffer chaine = new StringBuffer("");
HttpURLConnection connection = null;
try {
URL url = new URL(stringUrlShipments);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Content-Length", xmlstring.getBytes().length + "");
connection.setRequestProperty("SOAPAction", "http://35.15.85.55:8080/ServiceTransfer/GetAllOrdersOfShipment");
for(Map.Entry<String, String> entry : mHeaders.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
connection.setRequestProperty(key,value);
}
connection.setRequestMethod("POST");
connection.setDoInput(true);
OutputStream outputStream = connection.getOutputStream();
outputStream.write(xmlstring.getBytes("UTF-8"));
outputStream.close();
connection.connect();
status = connection.getResponseCode();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
Log.i("HTTP Client", "HTTP status code : " + status);
}
InputStream inputStream = null;
try {
inputStream = connection.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
return inputStream;
}
출처 : https://stackoverflow.com/questions/297586/how-to-call-a-soap-web-service-on-android
'개발 > 안드로이드' 카테고리의 다른 글
LocalBroadcastManager를 사용하는 방법 (0) | 2023.03.06 |
---|---|
"java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema" 오류 수정하기 (0) | 2023.03.06 |
안드로이드 스튜디오 오류 "Android Gradle 플러그인은 실행하기 위해 Java 11이 필요합니다. 현재 Java 1.8을 사용하고 있습니다." (0) | 2023.03.05 |
UI 스레드에서 코드 실행하기 (0) | 2023.03.05 |
"Looper.prepare()를 호출하지 않은 스레드 내에서 핸들러를 생성할 수 없습니다."오류 수정하기 (0) | 2023.03.05 |