मेरे पास एक webservice है जिसके लिए मैं क्लाइंट बनाने की कोशिश कर रहा हूं।साबुन ui जेनरेट कोड
मैं निम्नलिखित wsdl है:
http://www.cmicdataservices.com/datacenter/service.asmx?wsdl
यह प्रमाणीकरण की आवश्यकता है। डब्लूएसडीएल विवरण को देखते हुए मुझे कोई विधि नहीं है जो प्रमाणीकरण ऑब्जेक्ट लेता है, न ही उपयोगकर्ता नाम और पासवर्ड तर्क के रूप में। नेटबीन्स का उपयोग करके मैंने डब्लूएसडीएल के लिए जैक्स-डब्ल्यू स्रोत तैयार किए हैं। हालांकि मैं यह नहीं समझ सकता कि उसके बाद क्या करना है।
सोपुई का उपयोग करके मैं webservice से कनेक्ट कर सकता हूं और सभी विधियों को चला सकता हूं। लेकिन एक बार फिर, मैं इसे एक ऐसे ग्राहक में बनाना चाहता हूं जिसे मेरी बातचीत के बिना चलाया जा सके।
मेरी समस्या यह पता लगाने में आती है कि इस जेनरेट कोड का उपयोग कैसे करें, जो ऐसा लगता है कि netbeans.tv में एक वीडियो था (netbeans soapui प्लगइन वीडियो 2) जो तब से खो गया है। क्या किसी को किसी भी ट्यूटोरियल के बारे में पता है या किसी भी उदाहरण के बारे में पता है कि मैं webservice तक पहुंचने के लिए इस जेनरेट कोड का उपयोग कैसे कर सकता हूं?
तो मैं एक विधि CheckifAuthorized()
soapui में चल रहा है मैं निम्नलिखित एक्सएमएल
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:cmic="http://www.cmicdataservices.com/">
<soap:Header>
<cmic:Authentication>
<!--Optional:-->
<cmic:UserName>username</cmic:UserName>
<!--Optional:-->
<cmic:Password>password</cmic:Password>
</cmic:Authentication>
</soap:Header>
<soap:Body>
<cmic:CheckIfAuthorized/>
</soap:Body>
</soap:Envelope>
मैं तो साबुन ui में उस अनुरोध को चलाने के लिए और प्रतिक्रिया है कि प्रमाणीकरण एक सफलता थी वापस प्राप्त कर सकते मिल ।
package javaapplication7;
/**
*
* @author grant
*/
public class Main {
public static void main(String[] args) {
Boolean result = checkIfAuthorized();
System.out.println("The result is: " + result);
}
private static boolean checkIfAuthorized() {
javaapplication7.CMICDatacenterService service = new javaapplication7.CMICDatacenterService();
javaapplication7.CMICDatacenterServiceSoap port = service.getCMICDatacenterServiceSoap();
return port.checkIfAuthorized();
}
}
यह निम्न त्रुटि
run:
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Server was unable to process request. ---> Object reference not set to an instance of an object.
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:111)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
at $Proxy30.checkIfAuthorized(Unknown Source)
at javaapplication7.Main.checkIfAuthorized(Main.java:24)
at javaapplication7.Main.main(Main.java:17)
Java Result: 1
साथ विफल हो जाएगा यह एक ही समस्या मैं है:
jax-ws NetBeans के साथ और soapui साथ तैयार किए गए कोड के साथरूप में अच्छी तरह मैं निम्नलिखित है सेवा के लिए अजगर का उपयोग करने की कोशिश करते समय भाग गया। मैंने तब से जावा के साथ जाने के लिए चुना है क्योंकि मुझे लगता है कि मैं एक्सएमएल को पार्स करने और ऑब्जेक्ट्स बनाने पर त्वरित बदलाव कर सकता हूं क्योंकि मेरे पास पहले से ही बनाई गई संस्थाएं हैं।
धन्यवाद।
अनुदान
मैं इस जवाब देने के लिए क्योंकि मैं अभी भी यह पता लगाने की मैं यहाँ क्या कर सकते हैं चाहते हैं नहीं करना चाहता था, लेकिन मैं सिर्फ निम्नलिखित के साथ हाथ से अनुरोध लेखन अंत किया। अब मैं इसे सिर्फ एक एक्सएमएल ऑब्जेक्ट में परिवर्तित कर सकता हूं और अपने रास्ते के बारे में सोच सकता हूं, लेकिन मुझे लगता है कि सोपूई यह सब आसान बनाता है। क्या मैं सच में समझ में नहीं आता कि कैसे soapui उपयोग करने के लिए इस अनुरोध का निर्माण और अपने प्रोजेक्ट में शामिल करने के लिए है:
public class Main {
public final static String DEFAULT_SERVER =
"http://www.cmicdataservices.com/datacenter/service.asmx";
public final static String SOAP_ACTION =
"http://www.cmicdataservices.com/CheckIfAuthorized";
public static void main(String[] args) {
String server = DEFAULT_SERVER;
String UserName = "Username";
String Password="Password";
try{
URL url = new URL(server);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/soap+xml; charset=utf-8");
connection.setRequestProperty("Host", "www.cmicdataservices.com");
OutputStream out = connection.getOutputStream();
Writer wout = new OutputStreamWriter(out);
// Uncomment the following and comment out the previous two lines to see your xml
//BufferedWriter wout = new BufferedWriter(new FileWriter("/tmp/testXML.xml"));
//Start writing soap request - Envelope
wout.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n");
wout.write("<soap12:Envelope ");
wout.write("xmlns:xsi=");
wout.write("'http://www.w3.org/2001/XMLSchema-instance' ");
wout.write("xmlns:xsd=");
wout.write("'http://www.w3.org/2001/XMLSchema' ");
wout.write("xmlns:soap12=");
wout.write("'http://www.w3.org/2003/05/soap-envelope'>\r\n");
//Soap request header start
wout.write("<soap12:Header>\r\n");
//Start writing soap request - Authentication
wout.write("<Authentication xmlns=");
wout.write("'http://www.cmicdataservices.com/'>\r\n");
wout.write("<UserName>" + UserName + "</UserName>\r\n");
wout.write("<Password>" + Password + "</Password>\r\n");
// End Authentication
wout.write("</Authentication>\r\n");
//End the header
wout.write("</soap12:Header>\r\n");
//Start writing the body
wout.write("<soap12:Body>");
wout.write("<GetCurrentDataVer1 xmlns=");
wout.write("'http://www.cmicdataservices.com/' />\r\n");
// End the Body
wout.write("</soap12:Body>\r\n");
// End the Envelope
wout.write("</soap12:Envelope>\r\n");
wout.flush();
wout.close();
//BufferedWriter fout = new BufferedWriter(new FileWriter("/tmp/testXMLResponse.xml"));
InputStream in = connection.getInputStream();
createFile(in, "/tmp/testXMLResponse.xml");
}
catch (IOException e) {
System.err.println(e);
}
}
public static void createFile(InputStream io, String fileName) throws IOException {
FileOutputStream fout = new FileOutputStream(fileName);
byte[] buf = new byte[256];
int read = 0;
while ((read = io.read(buf)) != -1){
fout.write(buf, 0, read);
}
}
@grantk ने यह हमारे मुद्दे को हल किया? – tgkprog