如何通过 SOAP 消息传递参数以使用 Web 服务的参数化方法
我写了一个java SOAP WebService。以及消费者。如果我向不带参数的方法发送 SOAP 消息。一切正常,收到了正确的响应。
但是,我无法使用具有参数的方法。我的 SOAP 消息以以下模式存储在以下字符串中。
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
"<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">"+
"<S:Header/>"+
"<S:Body>"+
"<ns2:addPerson xmlns:ns2=\"http://service.cass.com/\">"+
"<fName xsi:type=\"xsd:string\">vbn</fName>"+
"<lName xsi:type=\"xsd:string\">yyyy</lName>"+
"<gender xsi:type=\"xsd:string\">879</gender>"+
"<age xsi:type=\"xsd:int\">90</age>"+
"</ns2:addPerson>"+
"</S:Body>"+
"</S:Envelope>";
方法原型为: public boolean addPerson(String fName, String lName, String 性别, int 年龄);
我收到以下异常。
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/ServerSide/ws/personService
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1305)
at com.cass.testRequest.makeSOAPRequest(testRequest.java:71)
at com.cass.testRequest.main(testRequest.java:37)
请注意,如果我发送一个不带参数的 SOAPMessage,则对于具有 0 个参数的方法。一切正常,我得到了适当的回应。在我看来,我在 SOAPMessage 中传递参数的方式有问题。请建议如何做到这一点。
问候, 阿吉夫
I have written a java SOAP WebService. and a consumer as well. if I send a SOAP message to a method with no parameters. it works all fine, a proper response is recieved.
But, I am unable to consume a method that have parameters. My SOAP message is stored in following string in following pattern.
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
"<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">"+
"<S:Header/>"+
"<S:Body>"+
"<ns2:addPerson xmlns:ns2=\"http://service.cass.com/\">"+
"<fName xsi:type=\"xsd:string\">vbn</fName>"+
"<lName xsi:type=\"xsd:string\">yyyy</lName>"+
"<gender xsi:type=\"xsd:string\">879</gender>"+
"<age xsi:type=\"xsd:int\">90</age>"+
"</ns2:addPerson>"+
"</S:Body>"+
"</S:Envelope>";
method prototype is:
public boolean addPerson(String fName, String lName, String gender, int age);
and I am getting following exception.
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/ServerSide/ws/personService
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1305)
at com.cass.testRequest.makeSOAPRequest(testRequest.java:71)
at com.cass.testRequest.main(testRequest.java:37)
Please notice that, if I send a SOAPMessage with no parameters, for a method with 0 parameters. It all works fine and I get a proper response. In my opinion, Something is wrong with the way I am passing parameters in SOAPMessage. Please suggest how to do that.
regards,
Aqif
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尚未定义
xsi
或xsd
命名空间。尝试类似以下的操作(但请参阅下面有关名称空间的正确版本的注释):(没有参数的方法不需要这些,这就是它在这种情况下工作的原因)。
已编辑:以下内容在 http://validator.w3.org/check 处验证为正确的 XML
虽然这并不意味着它符合 SOAP 架构...这将是接下来要检查的事情...
如果客户端使用 SOAP 1.1 而服务器使用 SOAP 1.2,您可能会遇到问题例如我认为命名空间不同。同样,不要混合两个版本的命名空间 - 它必须全部一致。
而且我认为 xsd 和 xsi 的最新命名空间现在是 2001 年而不是 1999 年,(我的错误,我使用的是旧的例子)。
但请参阅 SOAP 1.1 或 1.2(无论您使用哪个)的规范来了解明确的命名空间!
You haven't defined the
xsi
orxsd
namespaces. Try something like the following (but see comments below about correct veriosn of the namespaces):(These wouldn't be needed for your method with no parameters, which is why it worked in that case).
Edited: The following validates as correct XML at http://validator.w3.org/check
though that doesn't mean it conforms to the SOAP schema...that would be the next thing to check...
You may get problems if the client is using SOAP 1.1 and server is using SOAP 1.2 for example as I think the namespaces are different. Similarly, do not mix namespaces from the two versions - it must all be consistent.
And I think the up-to-date namespaces for xsd and xsi are now 2001 not 1999, (my mistake, I was using an old example).
But refer to the specs for SOAP 1.1 or 1.2 (whichever you are using) for the definitive namespaces!