Java calls the. NET WebService Ultimate Scenario (includes handling of SoapHeader)

Source: Internet
Author: User
Tags soap

First, preface: Today's department's products need to use the SMS function, need to walk the company's unified interface, and the SMS interface is developed by. NET, using two days to complete the use of Java to invoke. NET Web service, including the processing of the SOAP header. Second, the solution query the next Java in the support of soap, there are several scenarios, there are axis and xfire, and so on, I first chose Axis 1.4 version, then began to develop, there is a big hole ah. That is, the Getxxxx method in the properties of the class is parsed. The first letter of the property of the generated XML file is lowercase, and the generated XML for. NET does not work, the problem of light takes a long time, finally still decided to use Axis2 to do, with less than 2 hours to complete.     Third, what to do if you encounter problems? In the process of using axis1.4, I think the biggest problem is that the XML file generated by axis is inconsistent with. NET, so there is the problem, my approach is to install a wireshark to grab the package, and then compare to see which properties generated the wrong way to change the code, something half Times.     You can go to Google about the usage of Wireshark. For the use of axis program everyone directly with Axis2, to the official download a, if not clear the structure of the package, directly to the Lib all the jar packages are introduced to it. Lest a single one be cited.     Four, the process before said, need to seriously look at. NET returned XML file, if a method exists Soap:header, then on the Java side need to construct the header, there may be different methods for different headers, this need to see clearly.     Do not say, directly on the process and code. 1. Download Axis2, this is a must, the official download bar, and then unzip 2. Open the Command Console window, go to the bin directory, execute the command: Wsdl2java.bat-uri http://www.baidu.com/sample.asmx? wsdlSee the Red Parameters section, this must have.      3. A src directory is then generated in the Bin directory, and the generated two classes are copied to the project.     4. Then, that's basically the same as. NET Reference. NET Web service. OK, here's an example that includes header headers, passing complex types, and receiving return values
Servicestub stub = new Servicestub ();  This is the generated class, maybe your class name is not the same as mine            stub._getserviceclient (). GetOptions (). SetProperty ( Org.apache.axis2.transport.http.HTTPConstants.CHUNKED, boolean.false);             Add head verification              websoapheade Headere=new Websoapheade ();//The generated class here may be different from yours            websoaphead header=new websoaphead ();// This header is the header header for. NET Web Service             header.set.........//performs some property assignment operations, typically including user names and Passwords            Headere.setwebsoaphead (header); You need to add that head in.

  

Well, here we have the header information is constructed, this is only constructed, need to go to the following to execute an interface method when the head is passed in.            Then look at passing custom objects like I'm here for this texting business, the generated method is Sendsms (custom object, header information);              OK here we need to construct this custom object, the original. Net Sendsms method parameter is an array of custom objects, so what do we write here? Axis provides us with a wrapper object similar to Arrayofxxxx, which constructs the object and then adds the XXXX object in it.
Here we have basically done all the work of calling. NET WebService. I hope this article will bring you help.

Java calls the. NET WebService Ultimate Scenario (includes handling of SoapHeader)

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.