I'm looking at the SOAP output from a web service I'm developing, and I noticed something curious:
我正在查看我正在開發的Web服務的SOAP輸出,我發現了一些好奇的東西:
1234
2345
3456
Error1
Error2
I have two newKeys elements that are nil, and both elements insert a namespace reference for xsi. I'd like to include that namespace in the soapenv:Envelope element so that the namespace reference is only sent once.
我有兩個newKeys元素是nil,兩個元素都插入了xsi的命名空間引用。我想在soapenv:Envelope元素中包含該命名空間,以便命名空間引用只發送一次。
I am using WSDL2Java to generate the service skeleton, so I don't directly have access to the Axis2 API.
我正在使用WSDL2Java生成服務框架,因此我無法直接訪問Axis2 API。
2 个解决方案
#1
7
Using WSDL2Java
If you have used the Axis2 WSDL2Java tool you're kind of stuck with what it generates for you. However you can try to change the skeleton in this section:
如果您已經使用過Axis2 WSDL2Java工具,那么您將會遇到它為您生成的內容。但是,您可以嘗試更改此部分中的骨架:
// create SOAP envelope with that payload
org.apache.axiom.soap.SOAPEnvelope env = null;
env = toEnvelope(
getFactory(_operationClient.getOptions().getSoapVersionURI()),
methodName,
optimizeContent(new javax.xml.namespace.QName
("http://tempuri.org/","methodName")));
//adding SOAP soap_headers
_serviceClient.addHeadersToEnvelope(env);
To add the namespace to the envelope add these lines somewhere in there:
要將命名空間添加到信封,請在其中的某處添加以下行:
OMNamespace xsi = getFactory(_operationClient.getOptions().getSoapVersionURI()).
createOMNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");
env.declareNamespace(xsi);
Hand-coded
If you are "hand-coding" the service you might do something like this:
如果您是“手動編碼”服務,您可能會執行以下操作:
SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = fac.getDefaultEnvelope();
OMNamespace xsi = fac.createOMNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");
envelope.declareNamespace(xsi);
OMNamespace methodNs = fac.createOMNamespace("http://somedomain.com/wsinterface", "ns1");
OMElement method = fac.createOMElement("CreateEntityTypesResponse", methodNs);
//add the newkeys and errors as OMElements here...
Exposing service in aar
If you are creating a service inside an aar you may be able to influence the SOAP message produced by using the target namespace or schema namespace properties (see this article).
如果要在aar中創建服務,則可能會影響使用目標命名空間或模式命名空間屬性生成的SOAP消息(請參閱此文章)。
Hope that helps.
希望有所幫助。
#2
1
Other option is that the variable MY_QNAME has the prefix empty.
其他選項是變量MY_QNAME的前綴為空。
public static final QName MY_QNAME = new QName("http://www.hello.com/Service/",
"tagname",
"prefix");
So, if you fill it, then it works.
所以,如果你填寫它,那么它的工作原理。