Data interaction between systems is an important part of the WebService is a platform-independent, low-coupling, self-contained, programmable Web-based application that is more convenient to use, less gossip, and formally enters into about. NET to invoke the Java development interface.
There are many ways Java development webservice: Axis2, CXF, Xfire, etc., but in. NET call these interfaces can not implement the form of configuration IP to replace the call service, then how to solve this problem?
The author tests that the interface developed by the same framework can be configured to change the calling interface, if you need to reference the Java framework-based interface, referencing the service in Visual Stuido is not much to say here, as referenced by reference:
Change the calling interface by dynamically changing the URL after the reference is complete
1 New WEBSERVICE_SX. Service (); 2 objservice_sx. url = URL; 3 str = objservice_sx. Process (XMLSTR);
Similarly, when you need to invoke other Java interfaces by referencing a service and then calling through the configuration. How do I implement a configuration call interface? My way in Web. config is to configure the identity to be invoked and the URL for that identity to identify the different URLs by identifying the code as follows: Web. config
<!--Identity String -<AddKey= "Orgcodelist_axis2"value= "Up" /><AddKey= "ORGCODELIST_CXF"value= "3,4" /><AddKey= "Orgcodelist_xfire"value="" /><AddKey= "Orgcodelist_java"value="" /><!--identify the corresponding service address -<AddKey= "Orgcodelistandurl_axis2"value= "1,http://220.191.238.67:9091/axis2/services/;2,http://220.191.238.67:9092/axis2/services/" /><AddKey= "ORGCODELISTANDURL_CXF"value= "3,http://220.191.238.67:82/zy;4,http://220.191.238.67:84/zy" /><AddKey= "Orgcodelistandurl_xfire"value=""/><AddKey= "Orgcodelistandurl_java"value=""/>
The ASMX service first finds the identity in the identity string based on the identity in the incoming XML, such as Identity 1 belongs to AXIS2 development, and then to the corresponding identity service address to find the corresponding service of identity 1, replace the URL of the service that referred to Axis2 as the service address, You can do the right research without mistake.
[WebMethod] Public stringProcess (stringxmlstr) { stringOrgcodelist_axis2 = configurationmanager.appsettings["Orgcodelist_axis2"]. Trim (); stringORGCODELIST_CXF = configurationmanager.appsettings["ORGCODELIST_CXF"]. Trim (); XmlDocument xmldoc=NewXmlDocument (); 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": stringOrgcodelistandurl_axis2 = configurationmanager.appsettings["Orgcodelistandurl_axis2"]. Trim (); URL=GetUrl (Orgcode, ORGCODELISTANDURL_AXIS2); Webservice_sx. Service OBJSERVICE_SX=NewWEBSERVICE_SX. Service (); if(!string. IsNullOrEmpty (URL)) {objservice_sx. URL=URL; } STR=OBJSERVICE_SX. Process (XMLSTR); Break; Case "CXF": stringORGCODELISTANDURL_CXF = configurationmanager.appsettings["ORGCODELISTANDURL_CXF"]. Trim (); URL=GetUrl (Orgcode, ORGCODELISTANDURL_CXF); Webservice_qz. Service OBJSERVICE_QZ=NewWEBSERVICE_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>9995default</ Ret_code><ret_info> Success </ret_info></response></body>"; Break; } returnSTR;}
Private stringGETURL (stringOrgcode,stringList) { stringWsurl ="" ; string[] array = List.split (';'); for(inti =0; I < array. Length; i++) { string[] detail = array[i]. Split (','); if(detail[0]. ToString () = =Orgcode) {Wsurl= detail[1]. ToString (); Break; } } returnWsurl;}
Although the code is very simple, but this can be configured to solve the problem of calling Java interface, the individual in the use of the feeling is quite convenient, if there are better suggestions for improvement, welcome to communicate!
. NET implementation of the configuration call Java development WebService