最近在研究java的webservice,用的是cxf框架。一切順利,但是就是看著默認生成的命名空間前綴有點不爽
這個是介面
@WebService(targetNamespace="http://www.hehe.shabi.com",name="hehe",serviceName="heheService")
public interface ITestService {
@WebResult(name = "RESULT")
String syaHello(@WebParam(name="name") String name);
}
這個是實作
public class TestService implements ITestService {
public String syaHello(String name) {
return name + ",你好";
}
}spring里面的配置
<bean id="test" class="TestService"></bean>
<jaxws:endpoint implementor="#test" address="/test">
</jaxws:endpoint>
這個是用soapui生成的呼叫
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:hehe="http://www.hehe.shabi.com">
<soapenv:Header/>
<soapenv:Body>
<hehe:syaHello>
<name>34</name>
</hehe:syaHello>
</soapenv:Body>
</soapenv:Envelope>
syaHello 的前綴hehe是根據命名空間生成的,拿命名空間不就被固定了,不能更改成器他的,如改動的話,拿前綴也會發生變化,這個前綴可以單獨設定嗎?
回應更是有點尷尬了
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:syaHelloResponse xmlns:ns2="http://www.hehe.shabi.com">
<RESULT>34,你好</RESULT>
</ns2:syaHelloResponse>
</soap:Body>
</soap:Envelope>
這個ns2更是哪里冒出來的,可以自由設定嗎?syaHelloResponse 里面引入了ns2,這個可以在soap:Envelope中引入嗎?
看了網上說的,加了個屬性
<jaxws:endpoint implementor="#test" address="/test">
<jaxws:properties>
<entry key="soap.env.ns.map">
<map>
<entry value="http://www.hehe.shabi.net" key="hehe"></entry>
</map>
</entry>
</jaxws:properties>
</jaxws:endpoint>
呼叫沒有什么變化,但是回應就有點看不懂了
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:hehe="http://www.hehe.shabi.net">
<soap:Body>
<ns2:syaHelloResponse xmlns:ns2="http://www.hehe.shabi.com">
<RESULT>34,你好</RESULT>
</ns2:syaHelloResponse>
</soap:Body>
</soap:Envelope>
求助命名空間這個前綴具體要怎么設定?
uj5u.com熱心網友回復:
怎么能沒人呢,webservice這么成熟的技術了。。。。。。。。。。。。。。。。。。uj5u.com熱心網友回復:
。。。。。。。。。。。。。。。。。。。。。。。。uj5u.com熱心網友回復:
大神,您的name怎么加命名空間前綴呢?現在我在用cxf發布webservice遇到倆個問題:1、修改命名空間只能修改默認命名空間的包名么?2、輸入引數為物體類,發布的報文物體類的前面怎么加命名空間前綴呢?uj5u.com熱心網友回復:
按照http://cxf.547215.n5.nabble.com/How-to-customize-namespaces-position-and-prefix-in-CXF-response-td3423069.html這個的說明,應該在.xml組態檔中加<entry key="disable.outputstream.optimization" value="https://bbs.csdn.net/topics/true"/>
XML檔案的配置應該是
<jaxws:endpoint id="doubleHotline" implementor="#doubleHotlineService" address="/doubleHotline">
<jaxws:properties>
<entry key="soap.env.ns.map">
<map>
<entry value="http://esb.lzccb.com" key="esb"></entry>
<entry value="http://esb.lzccb.com/business/callcenter/DouHotLineService" key="douh"></entry>
</map>
</entry>
<entry key="disable.outputstream.optimization" value="https://bbs.csdn.net/topics/true"/>
</jaxws:properties>
<jaxws:inInterceptors>
<ref bean="loggingInInterceptor"/>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<ref bean="loggingOutInterceptor" />
</jaxws:outInterceptors>
</jaxws:endpoint>
最后用SoapUI測驗出來的回應報文是:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:esb="http://esb.lzccb.com" xmlns:douh="http://esb.lzccb.com/business/callcenter/DouHotLineService">
<soap:Header>
<esb:RouteInformation>
<esb:SourceId>?</esb:SourceId>
<esb:AuthCode>?</esb:AuthCode>
<esb:GoalId>?</esb:GoalId>
<esb:ServiceName>?</esb:ServiceName>
<esb:OperationName>?</esb:OperationName>
<esb:RouteMsgId>?</esb:RouteMsgId>
<esb:TimeOut>?</esb:TimeOut>
<esb:RelatesTo>?</esb:RelatesTo>
</esb:RouteInformation>
</soap:Header>
<soap:Body>
<douh:doubleHotLineResponse>
<douh:ResponseType>E</douh:ResponseType>
<douh:ResponseCode>111000</douh:ResponseCode>
<douh:ResponseMessage>明細欄位內容不符合規范</douh:ResponseMessage>
<douh:doubleHotLineRespData/>
</douh:doubleHotLineResponse>
</soap:Body>
</soap:Envelope>
uj5u.com熱心網友回復:
最后命名空間前綴是怎么去掉的?轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/133851.html
標籤:XML/XSL
上一篇:使用table標簽進行表格布局
下一篇:jsp中實作下拉復選框
