将名称空间声明从有效负载移动到轴创建的Web服务上的信封 [英] Move namespace declaration from payload to envelope on an axis created web service

查看:64
本文介绍了将名称空间声明从有效负载移动到轴创建的Web服务上的信封的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用axis和eclipse创建了一个Web服务客户端,该客户端不适用于我的Web服务提供商. Web服务客户端创建的消息如下所示:

I just created a web service client using axis and eclipse that does not work with my web service provider. The message created by the web service client looks like this:

<?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>
    <enviarMensajeRequest 
       xmlns="http://www.springframework.org/spring-ws/Imk-Zenkiu-Services">
      <usuario>someuser</usuario>
      <clave>somepassword</clave>
      <mensaje>somemessage</mensaje>
      <contacto>
        <buzonSMS>somenumber</buzonSMS>
        <primerNombre>somefirstname</primerNombre>
        <primerApellido>somelastname</primerApellido>
      </contacto>
    </enviarMensajeRequest>
  </soapenv:Body>
</soapenv:Envelope>

我认为该消息没有错,但我的提供者坚持认为该消息应为:

I see nothing wrong with the message but my provider insists the message should be:

<?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" 
  xmlns:imk="http://www.springframework.org/spring-ws/Imk-Zenkiu-Services">
  <soapenv:Body>
     <imk:enviarMensajeRequest>
        <imk:usuario>someuser</imk:usuario>
        <imk:clave>somepassword</imk:clave>
        <imk:mensaje>somemessage</imk:mensaje>
        <imk:contacto>
           <imk:buzonSMS>somenumber</imk:buzonSMS>
           <imk:primerNombre>somefirstname</imk:primerNombre>
           <imk:primerApellido>somelastname</imk:primerApellido>
        </imk:contacto>
     </imk:enviarMensajeRequest>
  </soapenv:Body>
</soapenv:Envelope>

请注意名称空间声明从enviarMensajeRequest移到soapenv:Envelope,并在参数上使用imk:进行限定.我在此过程中尝试了许多组合,但是我的Web服务,wsdl和xml知识非常有限.提供者说,除了告诉我这件事,他们无能为力.有任何想法吗?也许我可以使用另一个框架来创建正确的客户端.

Notice the namespace declaration moving from the enviarMensajeRequest to the soapenv:Envelope and the qualification with imk: on the parameters. I've tried many combinations on the process but my web service, wsdl and xml knowledge is very limited. The provider says that they can't help beyond telling me this. Any ideas? Perhaps a different framework that I can use to create the correct client.

推荐答案

您的提供者错误,消息在语义上是等效的;你的不合格,他们的合格.您正在使用Axis还是Axis2?如果您使用的是Axis,建议您使用Axis2以获得更健壮,符合标准的SOAP堆栈(这两种产品都不好,但Axis2的情况不太严重).

Your provider is wrong, the messages are semantically equivalent; yours is unqualified, theirs is qualified. Are you using Axis or Axis2? If you're using Axis, I suggest you switch to Axis2 for a more robust, standards-compliant SOAP stack (both products are bad, but Axis2 is less-bad).

我假设您正在使用wsdl2java创建客户端?如果您无法使用此工具以自己喜欢的方式生成消息,那么最好的选择就是以编程方式生成消息. 使用Axis2,您可以使用AXIOM API进行此操作.有关某些API用法示例,请参见此链接.请注意,对于大多数方法,例如

I assume you are creating your client with wsdl2java? If you can't get this tool to generate the message the way you like, then your best bet is to generate the message programmatically. With Axis2, you can do this with the AXIOM API. See this link for some example API usage. Note that with most of the methods, e.g. createOMElement, you optionally pass the namespace prefix. So, if your provider requires it, then you could pass a String containing "imk" as the namespacePrefix parameter.

如果最终以编程方式执行此操作,而只打算编写一个简单的客户端,那么我强烈建议您放弃Axis/Axis2方法,并使用

If you end up doing this programmatically and you are only going to be writing a simple client, then I STRONGLY suggest you abandon the Axis/Axis2 approach and use the JAX-WS stack instead, as it is part of Java since 1.6. The API is cleaner and the documentation is better. For example, following is a very simple client I wrote to send a SOAP request to our JIRA server. The sample code creates both qualified and unqualified elements.

QName port = new QName(endpoint, "subversionsoapservice-v2");
QName serviceName = new QName(endpoint, "ISubversionSoapServiceService");

Service service = Service.create(serviceName);
service.addPort(port, SOAPBinding.SOAP11HTTP_BINDING, endpoint);

Dispatch<SOAPMessage> dispatch = service.createDispatch(port, SOAPMessage.class, Service.Mode.MESSAGE);
MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
SOAPMessage request = factory.createMessage();
SOAPBody body = request.getSOAPBody();

SOAPElement reindexRepository = body.addChildElement("reindexRepository", "jira", "http://soap.ext.plugin.jira.atlassian.com");
SOAPElement in0 = reindexRepository.addChildElement("in0");
in0.addTextNode("test");

request.saveChanges();
dispatch.invoke(request);

客户端发送的XML如下:

The XML sent by the client looks like this:

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body>
        <jira:reindexRepository xmlns:jira="http://soap.ext.plugin.jira.atlassian.com">
            <in0>test</in0>
        </jira:reindexRepository>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

这篇关于将名称空间声明从有效负载移动到轴创建的Web服务上的信封的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆