web services - From WDSL to java -


i've been tasked querying soap client in java , i'm bit confused how move forward.

the first thing did use wizdler chrome plugin prototype soap request. soap "envelop" must of format believe work.

<envelope xmlns="http://www.w3.org/2003/05/soap-envelope"> <body>     <getmyprojectcharges xmlns="http://company.iwweb.data.service.projectcharges">         <employee>[string?]</employee>         <fiscalyear>[string?]</fiscalyear>         <apikey>[string?]</apikey>         <appname>[string?]</appname>     </getmyprojectcharges> </body> </envelope> 

next i've gone through various tutorial how build soap envelop in java keep getting strange situation i'm getting <soap-env: prefixes on , when take generated envelop , try paste chrome plugin doesn't work.

so i'm wondering go here? realize soap pretty heavy protocol , maybe confusing me i'm looking (for now) is:

1) generate soap request in java matches format above, , print out results.

i understand "might" have option of maven or program generate class files me wdsl i'm not sure either. thanks!

any appreciated.

you have 2 way soap request.

solution 1

if use netbeans code ide, have create project, right click on package , choose new >> web service client. insert url of soap endpoint , click ok. if have jax-ws/metro extension installed in ide netbeans generate necessary classes invoke service programmatically. (ask me if have troubles)

solution 2

you realize soap request using javax.xml

private soapmessage invoke(qname servicename, qname portname,         string soapactionuri) throws exception {      service service = service.create(servicename);     service.addport(portname, soapbinding.soap11http_binding, endpointurl);      dispatch dispatch = service.createdispatch(portname,             soapmessage.class, service.mode.message);      dispatch.getrequestcontext().put(dispatch.soapaction_use_property, new boolean(true));     dispatch.getrequestcontext().put(dispatch.soapaction_uri_property, soapactionuri);      messagefactory messagefactory = messagefactory.newinstance();     soapmessage message = messagefactory.createmessage();      soappart soappart = message.getsoappart();     soapenvelope envelope = soappart.getenvelope();     soapbody body = envelope.getbody();      source source = new domsource(getquerystring());     soappart.setcontent(source);      message.savechanges();      system.out.println(message.getsoapbody().getfirstchild().gettextcontent());      soapmessage response = (soapmessage) dispatch.invoke(message);      return response; }  private node getquerystring() throws saxexception, ioexception, parserconfigurationexception {     stringbuilder builder = new stringbuilder();     builder.append("<soapenv:envelope");     // create body     builder.append("</soapenv:body>");     builder.append("</soapenv:envelope>");      documentbuilderfactory docfactory = documentbuilderfactory.newinstance();     documentbuilder docbuilder = docfactory.newdocumentbuilder();     document stringdocument = docbuilder.parse(new inputsource(new stringreader(builder.tostring())));      return stringdocument; } 

and call service use

string targetnamespace = "your target namespace"; qname servicename = new qname(targetnamespace, "your service name"); qname portname = new qname(targetnamespace, "your port name"); string soapaction = "your soap action"; soapmessage response = invoke(servicename, portname, soapaction); if (response.getsoapbody().hasfault()) {      system.out.println(response.getsoapbody().getfault()); } 

p.s. forgive me english :(


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -