| |

VerySource

 Forgot password?
 Register
Search
View: 568|Reply: 1

Questions about Soap transmitting\and receiving a Soap message: How can the client receive the Soap message from the se

[Copy link]

5

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-1-29 11:40:02
| Show all posts |Read mode
The following code sends a message to the server:
URLEndpoint myEndpoint = new URLEndpoint ("http://127.0.0.1:8080/axis/HelloService.jws?wsdl");
SOAPConnection con = scf.createConnection ();
SOAPMessage msg = mf.createMessage ();
con.call (msg, myEndpoint);
In this way, a Soap message can be sent to the server and the server can execute and respond. So, how do clients receive a server response message
Reply

Use magic Report

5

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-3-5 15:45:01
| Show all posts
Get it:
The con.call (msg, myEndpoint); method returns a SOAPMessage from the server, as long as you give it a SOAPMessage variable.
The code is written like this: msg = con.call (msg, myEndpoint);

The entire code is as follows:
Client:
import javax.xml.soap. *;
import javax.xml.messaging. *;

public class CustomSoap {
public static void myCustomSoap () {
try {
URLEndpoint myEndpoint = new URLEndpoint ("http://127.0.0.1:8080/axis/HelloService.jws?wsdl");
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance ();
SOAPConnection con = scf.createConnection ();
MessageFactory mf = MessageFactory.newInstance ();
SOAPMessage msg = mf.createMessage ();
SOAPPart sp = msg.getSOAPPart ();
SOAPEnvelope envelope = sp.getEnvelope ();
SOAPBody bdy = envelope.getBody ();
SOAPBodyElement gltp = bdy.addBodyElement (envelope.createName (
"sayHello", "soapenv",
"http://schemas.xmlsoap.org/soap/encoding/"));
gltp.addChildElement ("zzm"). addTextNode ("The Frist MySoap");
con.call (msg, myEndpoint);
System.out.println ("Soap message transmitted:");
msg.writeTo (System.out);
System.out.println ("");
System.out.println ("Soap message in response to the server:");
msg = con.call (msg, myEndpoint);
msg.writeTo (System.out);
}
catch (Exception e) {
System.out.println (e.toString ());}
}
public static void main (String [] args) {
myCustomSoap ();
}
}

The information printed on the control panel is as follows:
Soap message transmitted:
<? xml version = "1.0" encoding = "UTF-8"?>
<soapenv: Envelope xmlns: soapenv = "http://schemas.xmlsoap.org/soap/envelope/" xmlns: xsd = "http://www.w3.org/2001/XMLSchema"
                  xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance">
<soapenv: Body>
<soapenv: sayHello xmlns: soapenv = "http://schemas.xmlsoap.org/soap/encoding/">
<soapenv: zzm> The Frist MySoap </ soapenv: zzm>
</ soapenv: sayHello>
</ soapenv: Body>
</ soapenv: Envelope>

Respond to the server's Soap message:
<? xml version = "1.0" encoding = "utf-8"?>
<soapenv: Envelope xmlns: soapenv = "http://schemas.xmlsoap.org/soap/envelope/" xmlns: xsd = "http://www.w3.org/2001/XMLSchema"
                  xmlns: xsi = "http://www.w3.org/2001/XMLSchemainstance">
<soapenv: Body>
<soapenc: sayHelloResponse soapenv: encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/" xmlns: soapenc = "http://schemas.xmlsoap.org/soap/encoding/">
<sayHelloReturn xsi: type = "xsd: string"> Hello: The Frist MySoap </ sayHelloReturn>
</ soapenc: sayHelloResponse>
</ soapenv: Body>
</ soapenv: Envelope>

Services on the server:
public class HelloService
{
public String sayHello (String username)
{
return "Hello:" + username;
}
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list