. Net calls the soapheader information of the WebService encapsulated by Java xfire.

Source: Internet
Author: User

. Net calls the WebService encapsulated soapheader information released by Java xfire, Which is troublesome and needs to be changed to the proxy class.Code.

Java Server Verification Code

Package chachaba. map. service; import Org. codehaus. xfire. messagecontext; import Org. codehaus. xfire. handler. export acthandler; import Org. JDOM. element; public class authenticationhandler extends acthandler {public void invoke (messagecontext CFX) throws exception {If (CFX. getinmessage (). getheader () = NULL) {Throw new Org. codehaus. xfire. fault. xfirefault ("the request must contain verification information", org. codehaus. xfire. fault. xfirefault. sender);} element token = CFX. getinmessage (). getheader (). getchild ("authenticationtoken"); If (token = NULL) {Throw new Org. codehaus. xfire. fault. xfirefault ("the request must contain authentication information", org. codehaus. xfire. fault. xfirefault. sender);} string username = token. getchild ("username "). getvalue (); string Password = token. getchild ("password "). getvalue (); try {// for authentication, only the user of yw88 @ ccc0c325-fe67-4cad-baab-4ad9ebb4f927 is the authorized user if (username. equals ("yw88") & password. equals ("ccc0c325-fe67-4cad-baab-4ad9ebb4f927") // This statement does not display system. out. println ("authenticated"); else throw new exception ();} catch (exception e) {Throw new Org. codehaus. xfire. fault. xfirefault ("invalid user name and password", org. codehaus. xfire. fault. xfirefault. sender );}}}

The. NET call process is as follows:

1. Generate proxy classes, such as stallsservice. CS

2. Add a soapheader class to the proxy class. The complete code is as follows:

 
Public class authenticationtoken: soapheader {Public String username; Public String password ;}

3. Add soapheader class parameters to the proxy class,

 
Public authenticationtoken header = new authenticationtoken ();

4. Add the property code to the Method

 
[Soapheader ("Header")] public void deletter ter ([system. XML. serialization. xmlelementattribute (isnullable = true)] string in0) {This. invoke ("deleteinter", new object [] {in0 });}

5. Set the namespace in the proxy class to null,

 
[System. Web. Services. webservicebindingattribute (name = "stallsservicehttpbinding", namespace = "")]

6. The client call code is as follows:

Stallsservice client = new stallsservice (); authenticationtoken myheader = new authenticationtoken (); myheader. username = "username"; myheader. password = "password"; client. header = myheader; client. deletter ter ("9999 ");

OK

Related Article

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.