【问题标题】:JAX-WS wants soap webservice response in particular formatJAX-WS 需要特定格式的肥皂网络服务响应
【发布时间】:2016-10-15 11:35:30
【问题描述】:

我已经使用 spring 实现了 JAX 肥皂网络服务。我的方法签名是

字符串验证(字符串参数)

为此我有服务:

@WebService
public class ValidationWS
{

    TestValidation TestValidation;
    @Resource(name = "wsContext")
    WebServiceContext wsContext;

    /**
     * @return the testValidation
     */
    @WebMethod(exclude = true)
    public TestValidation getTestValidation()
    {
        return testValidation;
    }

    @WebMethod(exclude = true)
    public void setTestValidation(final TestValidation testValidation)
    {
        this.testValidation = testValidation;
    }


    @WebMethod(operationName = "validateToken")
    public String validateToken(final String argu)
    {
        return testValidation.validate(argu);
    }

}

一切都很好并得到以下响应:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:validateResponse xmlns:ns2="http://webservice.validation.test.com/">
         <return><validate><returnCode>InvalidToken</returnCode></validate></return>
      </ns2:validateResponse>
   </S:Body>
</S:Envelope>

但我想要以下格式的回复意味着我的结果不在 tag 下。希望得到以下格式的回复:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns1:validateResponse xmlns:ns1="http://webservice.validation.test.com/">
         <validateResult xsi:type="xsd:String"><validate><returnCode>InvalidToken</returnCode></validate></validateResult>
      </ns1:validateResponse>
   </S:Body>
</S:Envelope>

请告诉我如何实现这一点。正如尝试其他方式但无法找到解决方案。 提前致谢。

【问题讨论】:

    标签: spring web-services soap jax-ws


    【解决方案1】:

    我已找到答案,并在服务中做了以下更改:

    @WebService
    public class ValidationWS
    
    {
    
    TestValidation TestValidation;
    @Resource(name = "wsContext")
    WebServiceContext wsContext;
    
    /**
     * @return the testValidation
     */
    @WebMethod(exclude = true)
    public TestValidation getTestValidation()
    {
        return testValidation;
    }
    
    @WebMethod(exclude = true)
    public void setTestValidation(final TestValidation testValidation)
    {
        this.testValidation = testValidation;
    }
    
    @WebResult(name = "TokenResult", targetNamespace = "http://token.test.com/", partName = "TokenResult")
    @WebMethod(operationName = "validateToken")
    public String validateToken(@WebParam(partName = "token", name = "token", targetNamespace = "http://token.test.com/")final String token)
    {
        return testValidation.validate(argu);
    }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      • 2017-01-16
      • 2017-12-10
      相关资源
      最近更新 更多