Some issues and precautions for calling. Net WebService using Java

Source: Internet
Author: User

Finally, in the study of GWT, we need to use the. NET WebService.CodeThere are many problems.

To call. Net WebService in Java, an axis package is required. Download the package and reference it.

 

When referencing, you need to pay attention to some minor issues.

Java end

Public String servicelogon (string user, string PWD) throws serviceexception <br/>{< br/> string url = "http: // localhost/WebServices/service. asmx "; <br/> service = new service (); <br/> call = (CALL) service. createcall (); <br/> // We Have To figure our The namespace. the Java doesn' t know where is the namespace <br/> call. setoperationname (New QNAME ("http: // localhost/WebServices/service. asmx "," Logon "); </P> <p> call. addparameter (New QNAME ("http: // localhost/WebServices/service. asmx "," username "), xmltype. xsd_string, javax. XML. RPC. parametermode. in); <br/> call. addparameter (New QNAME ("http: // localhost/WebServices/service. asmx "," password "), xmltype. xsd_string, javax. XML. RPC. parametermode. in); <br/> string res = ""; <br/> try {<br/> call. settargetendpointaddress (new URL ("http: // localhost/WebServices/service. asmx "); <br/> res = (string) Call. invoke (new object [] {user, PWD}); <br/>} catch (malformedurlexception E) {<br/> // todo auto-generated Catch Block <br/> E. printstacktrace (); <br/>} catch (RemoteException e) {<br/> // todo auto-generated Catch Block <br/> E. printstacktrace (); <br/>}< br/> return res; <br/>}< br/>

One small problem that needs to be noted is that when referencing, we should point out the namespace of. Net WebService. Different Code namespaces are different.

When adding parameters, you must generate a new QNAME.

Call. addparameter (New QNAME ("http: // localhost/WebServices/service. asmx "," username "), xmltype. xsd_string, javax. XML. RPC. parametermode. in); if it is not new, the received parameter will be null.

 

. Net end.

Using system; <br/> using system. web; <br/> using system. web. services; <br/> using system. web. services. protocols; <br/> [WebService (namespace = "http: // localhost/WebServices/service. asmx ")] // namespace <br/> [soapdocumentservice (routingstyle = soapserviceroutingstyle. requestelement)] // very import must figure out <br/> public class service: system. web. services. webService <br/> {<br/> Public Service () {<br/> // uncomment the following line if using designed components <br/>/initializecomponent (); <br/>}< br/> [webmethod] <br/> Public String helloworld () {<br/> return "Hello World "; <br/>}< br/> [webmethod] <br/> Public String Logon (string username, string password) <br/> {<br/> If (username = "Steven _wang" & Password = "123123") <br/> return "Welcome to Asp.net WebService "; <br/> else <br/> return "username:" + username + ", password:" + password; <br/>}</P> <p >}< br/>

 

This code is available in vs2005 framework2.0, windowxp, iis5.0

Jdk1.6, eclipse3.3, axis1.4

Debugging is successful.

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.