Java Call Donet WebService method

Source: Internet
Author: User

Donet's WebService

Browser Access test address: Http://192.168.4.17/JLWWS/sendCommand.asmx, appeared

Click the Getdevicevalue method that appears

The XML code is pasted again:
post/jlwws/sendcommand.asmx http/1.1host:192.168.4.17content-type:text/xml; Charset=utf-8content-length: Lengthsoapaction: "Http://tempuri.org/getDeviceValue"<?XML version= "1.0" encoding= "Utf-8"?><Soap:envelopeXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd= "Http://www.w3.org/2001/XMLSchema"Xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/">  <Soap:body>    <Getdevicevaluexmlns= "http://tempuri.org/">      <N>Int</N>      <s>String</s>    </Getdevicevalue>  </Soap:body></Soap:envelope>http/1.1 okcontent-type:text/xml; charset=utf-8content-length:length<?XML version= "1.0" encoding= "Utf-8"?><Soap:envelopeXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd= "Http://www.w3.org/2001/XMLSchema"Xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/">  <Soap:body>    <Getdevicevalueresponsexmlns= "http://tempuri.org/">      <Getdevicevalueresult>String</Getdevicevalueresult>    </Getdevicevalueresponse>  </Soap:body></Soap:envelope>
And then

Java method:
 PublicString cc () {string result= ""; Try{Service service=NewService (); Call Call=(call) Service.createcall (); Call.setoperationname (NewQName ("http://tempuri.org/"," Getdevicevalue ")); Call.addparameter (NewQName ("http://tempuri.org/"," N "), Org.apache.axis.encoding.XMLType.XSD_INT, Javax.xml.rpc.ParameterMode.IN); Call.addparameter (NewQName ("http://tempuri.org/"," s "), Org.apache.axis.encoding.XMLType.XSD_STRING, Javax.xml.rpc.ParameterMode.IN); Call.settargetendpointaddress (NewURL ("Http://192.168.4.17/JLWWS/sendCommand.asmx")); Call.setusesoapaction (true); Call.setsoapactionuri ("Http://tempuri.org/getDeviceValue"); //Soapservice soap = new Soapservice (); //soap.setname ("SendCommand1"); //call.setsoapservice (soap);result = (String) Call.invoke (NewObject[] {"1", "AAAAAAAAA"});          SYSTEM.OUT.PRINTLN (result); }Catch(Exception e) {e.printstacktrace (); }                    returnresult; }

Note the red part of the above code. First, the namespace attention should not be written wrong; second, if the parameter is an INT type, set the value of the string when the parameter, (Addparameter still want to Org.apache.axis.encoding.XMLType.XSD_INT).

Refer to a post on the CSDN forum that says:

The error message is as follows:
Axisfault
FaultCode: {http://schemas.xmlsoap.org/soap/envelope/}client
Faultsubcode:
FaultString: The server was unable to read the request. ---&gt; There was an error in the XML document (1, 582). ---&gt; The input string is not in the correct format.

==================

Although the XML is
<soap:Body>
<pubclientlogin xmlns= "http://NewCap.com/NewCapecWebService/" >
<appid>int</appid>
</PubClientLogin>
</soap:Body>
But the incoming parameter is entered as a string type,
Call.addparameter (New QName (targetnamespace, "AppID"), xmltype.xsd_int, parametermode.in);
Call.invoke (New object[]{""})

Post Address: http://bbs.csdn.net/topics/360243982

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.