C # calls Java WebService's topic

Source: Internet
Author: User
Tags soap java web

. NET NULL when data is passed to WebService double, int, DateTime server

recently was a C # call Java Web service trouble, query some information, but not exhaustive, so I did an example, found the problem, summed up ... I'm tired of making bricks.

problem Phenomenon:

In C #. NET calls Java ( using Xfire) developed WebService, the client is encapsulated in the object with the int attribute, when the object is uploaded to the server side, the server side can get the string type of attribute value, but cannot get the int type, Values for double and datetime types (NULL is obtained on the server)

Question Crux:

simply say how the WebService works. The client invokes a WebService method that first needs to wrap the method name and the parameters that need to be passed into XML (that is, the SOAP packet), usually via HTTP to the server side, and then the server resolves the XML to get the called method name and the parameters passed. It then invokes the corresponding method of the WebService instance. After the method completes, the returned results are packaged into XML (the SOAP response) and sent to the client, where the client parses the XML and gets the result returned. The key here is the process of transforming objects and XML into one another.

Because the server side aegis the object by a non-string property (Int,double,datetime. Sets the Nullable (nillable= "true") to pass a user object when the client invokes the service method Saveuser (jafuser user) . Sets a null value that can be null for a non-string property at the server side (the int type is 0,double type 0.0,datetime is null).

take int and double as examples:

Server-side program: Exampleservice provides saveuser (Jafuser user) method. Returns a string of concatenation of the user attribute. Where user has 3 properties: userId (int type), UserName (String type), weight (double type).

 

Problem-solving (2 steps):
1.web Service-side Xfire Aegis binding configuration.

JafUser.aegis.xml settings for object Jafuser transfer through XML

<mappings xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"

xsi:schemalocation= "Http://xfire.codehaus.org/schemas/1.0/mapping.xsd" >

<mapping>

<property name= "userId" style= "element" minoccurs= "0" maxoccurs= "1" nillable= "true"/>

<property name= "UserName" style= "element" minoccurs= "1" maxoccurs= "1" nillable= "false"/>

<property name= "Weight" style= "element" minoccurs= "1" maxoccurs= "1" nillable= "false"/>

</mapping>

</mappings>

2. Set when the client invokes.

VS2008 encapsulates a WebService reference, if WebService publishes an object consisting of a base data type: (Take Jafuser as an example)

A. When the non-string property of this object is set to minoccurs= "0" nillable= "true" (which means that the property can be empty), two properties are generated for the object's not string property, typically the property field, property Xxs Pecified ". Property name specified is a bool type, and the value of the property field is serialized to XML delivery only if this property is set to true. Otherwise, the server receives a value of 0 (int, receives 0) or 0.0 (double receives 0.0).

B. The non-string property of this object is set when the minoccurs= "1" maxoccurs= "1" nillable= "false" (indicates that the property cannot be empty, is required), and if the property is not assigned, the service end receives a value of 0.0

Report:

The

         attachment is an example, and the client is an VS2008 application. Service-side for the compiled program, after decompression directly to the inside of the Xfireservice folder into Tomcat WebApps directory, start the service, the browser input http://localhost:8080/xfireService/services /EXAMPLESERVICE?WSDL can see the service description file, after that, you can debug through the VS2008 client. If you have any questions, leave a message.

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.