JAX-WS 需要特定格式的 soap web 服务响应
JAX-WS wants soap webservice response in particular format
我已经使用 spring 实现了 JAX soap 网络服务。我的方法签名是
字符串验证(字符串参数)
为此我有服务:
@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>
但我想要以下格式的回复意味着我的结果不在标签下。想要以下格式的回复:
<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>
你能告诉我如何实现这一点吗?尝试过其他方式但无法找到解决方案。
提前致谢。
我找到了答案并在服务中做了以下更改:
@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);
}
}
我已经使用 spring 实现了 JAX soap 网络服务。我的方法签名是
字符串验证(字符串参数)
为此我有服务:
@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>
但我想要以下格式的回复意味着我的结果不在标签下。想要以下格式的回复:
<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>
你能告诉我如何实现这一点吗?尝试过其他方式但无法找到解决方案。 提前致谢。
我找到了答案并在服务中做了以下更改:
@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);
}
}