. Net implements configuration-based calling of JAVA-developed WebService and javawebservice

Source: Internet
Author: User

. Net implements configuration-based calling of JAVA-developed WebService and javawebservice

Data Interaction between systems is an important part. WebService is a platform-independent, low-coupling, self-contained, and programmable web-based application that is easy to use, in a few minutes, I officially started to talk about.. Net.

Currently, there are many ways to develop WebService in JAVA: Axis2, CXF, and xfire.. Net?

The author found that the interfaces developed in the same framework can be configured with URLs to change the calling interfaces, provided that JAVA interfaces based on different frameworks need to be referenced, the reference method of services in Visual Stuido is not described here, for example, reference method:

1 WebService_SX.Service objService_sx = new WebService_SX.Service (); 2 objService_sx.Url = url; 3 str = objService_sx.Process (XmlStr );Similarly, when other java interfaces need to be called, a service is referenced and then called through configuration. How can I implement configuration-based calling interfaces? My method is to configure the url of the identifier to be called and the corresponding URL in web. config, and identify different URLs through the identifier. The Code is as follows: web. config

<! -- Id string --> <add key = "orgCodeList_axis2" value = "1, 2"/> <add key = "orgCodeList_cxf" value = "3, 4"/> <add key = "orgCodeList_xfire" value = ""/> <add key = "orgCodeList_java" value = ""/> <! -- Identify the corresponding service address --> <add key = "orgCodeListAndUrl_axis2" value = "1, http: // 220.191.238.67: 9091/axis2/services/; 2, http: // 220.191.238.67: 9092/axis2/services/"/> <add key =" orgCodeListAndUrl_cxf "value =" 3, http: // 220.191.238.67: 82/zy; 4, http: // 220.191.238.67: 84/zy "/> <add key =" orgCodeListAndUrl_xfire "value =" "/> <add key =" orgCodeListAndUrl_java "value =" "/>

 

In the asmx service, first, find the ID in the ID String Based on the ID in the imported xml. For example, Id 1 belongs to axis2, search for the service corresponding to Id 1 in the service address corresponding to the corresponding identifier, and replace the url of the Service referenced in axis2 with the service address, then you can perform the correct investigation without holding an error.

[WebMethod] public string Process (string XmlStr) {string orgCodeList_axis2 = ConfigurationManager. appSettings ["orgCodeList_axis2"]. trim (); string orgCodeList_cxf = ConfigurationManager. appSettings ["orgCodeList_cxf"]. trim (); XmlDocument xmlDoc = new XmlDocument (); xmlDoc. loadXml (XmlStr); string str = ""; string orgCode = ""; string type = ""; string url = "";
OrgCode = this. GetParam (xmlDoc, "body/resquest/", "ORG_CODE", null );

If (orgCodeList_axis2.IndexOf (orgCode)>-1) {type = "axis2";} else if (orgCodeList_cxf.IndexOf (orgCode)>-1) {type = "cxf ";} switch (type) {case "axis2": string orgCodeListAndUrl_axis2 = ConfigurationManager. appSettings ["orgCodeListAndUrl_axis2"]. trim (); url = GetUrl (orgCode, orgCodeListAndUrl_axis2); WebService_SX.Service objService_sx = new WebService_SX.Service (); if (! String. isNullOrEmpty (url) {objService_sx.Url = url;} str = objService_sx.Process (XmlStr); break; case "cxf": string orgCodeListAndUrl_cxf = ConfigurationManager. appSettings ["orgCodeListAndUrl_cxf"]. trim (); url = GetUrl (orgCode, orgCodeListAndUrl_cxf); WebService_QZ.Service objService_qz = new WebService_QZ.Service (); if (! String. IsNullOrEmpty (url) {objService_qz.Url = url;} str = objService_qz.Process (XmlStr); break; default: str = "<? Xml version = \ "1.0 \" encoding = \ "UTF-8 \"?> <Body> <response> <ret_code> 9995 </ret_code> <ret_info> Successful </ret_info> </response> </body> "; break;} return str ;}
Private string GetUrl (string orgCode, string List) {string WSurl = ""; string [] array = List. split (';'); for (int I = 0; I <array. length; I ++) {string [] detail = array [I]. split (','); if (detail [0]. toString () = orgCode) {WSurl = detail [1]. toString (); break;} return WSurl ;}

Although the Code is very simple, it is very convenient to call the java interface through configuration. If you have better suggestions for improvement, please contact us!

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.