web services - Couldn't create SOAP message due to exception: XML reader error: com.ctc.wstx.exc.WstxParsingException: Undeclared namespace prefix "ws"
 -


i have created web service using jax-ws. when access web service getting following response:

<?xml version='1.0' encoding='utf-8'?><s:envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:body><s:fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope"><faultcode>s:client</faultcode><faultstring>couldn't create soap message due exception: xml reader error: com.ctc.wstx.exc.wstxparsingexception: undeclared namespace prefix "ws"&#xd;  @ [row,col {unknown-source}]: [1,169]</faultstring></s:fault></s:body></s:envelope> 

my web service is:

@webservice public interface helloservice {     @webmethod     string hello(@webparam(name = "name")string msg);    }   public class helloserviceiml implements helloservice { @override string hello(string msg){ return "hello" + msg; } }  public class mainws {      /**      * @param args      */     public static void main(string[] args) {         endpoint.publish("http://localhost:8085/hello", new helloserviceiml());     }  } 

client program:

public class postsoap {     public static void main(string[] args) throws exception {         // target url         string strurl = "http://localhost:8085/helloservice";         // soap action         string strsoapaction = "soapaction";         // file posted         string strxml = "<?xml version=\"1.0\" encoding=\"windows-1251\"?> " +                 "<soapenv:envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"> " +                 "<soapenv:header/> " +                               "<soapenv:body> <ws:hello> " +                 " <name>john</name> " +                      " </ws:hello> </soapenv:body> </soapenv:envelope> ";          // prepare http post         postmethod post = new postmethod(strurl);         post.setrequestbody(strxml);         post.setrequestheader("content-type", "text/xml");          // consult documentation web service         post.setrequestheader("soapaction", strsoapaction);         // http client         httpclient httpclient = new httpclient();         httpclient.getparams().setauthenticationpreemptive(true);         httpclient.getstate().setcredentials(authscope.any, new usernamepasswordcredentials("user", "pwd"));          // execute request         try {             int result = httpclient.executemethod(post);             // display status code             system.out.println("response status code: " + result);             // display response             system.out.println("response body: ");             system.out.println(post.getresponsebodyasstring());         } {             // release current connection connection pool once done             post.releaseconnection();         }     }   } 

please me solve problem.

it's right there

<ws:hello> " + " <name>john</name> " +      " </ws:hello> 

you have ws: namespace have not declared namespace anywhere.

you should have schema web service example (from springsource)

<holiday xmlns="http://mycompany.com/hr/schemas">     <startdate>2006-07-03</startdate>     <enddate>2006-07-07</enddate> </holiday> 

or

<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:ws="http://mycompany.com/hr/schemas"> 

see: http://static.springsource.org/spring-ws/site/reference/html/tutorial.html


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -