JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java Application Framework » Spring  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Spring Remote Services part2 Web services using SOAP
uxa





發文: 489
積分: 6
於 2007-12-14 14:13 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
小弟又來分享囉...這次是Spring Remote Service Web services using SOAP and JAX-RPC
和部署RMI一樣,先建立出interface
1
2
3
4
5
6
7
8
9
10
package com.springinaction.chapter08;
 
import javax.jws.WebMethod;
import javax.jws.WebService;
 
public interface CitationService {
 
  String getCitation();
}
 


實作部份,簡單地回傳固定字串
1
2
3
4
5
6
7
8
9
10
11
12
13
package com.springinaction.chapter08;
 
import javax.jws.WebService;
 
public class CitationServiceImpl implements CitationService {
 
  public String getCitation() {
    // TODO Auto-generated method stub
    return "Citation";
  }
 
}
 


接下來看到Spring的設定
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  <!-- declare WebService with XFire   -->
  <import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
 
  <bean id="citationService.xfire"
    class="org.codehaus.xfire.spring.remoting.XFireExporter">
    <property name="serviceFactory" ref="xfire.serviceFactory"></property>
    <property name="xfire" ref="xfire"></property>
    <property name="serviceBean" ref="citationService"></property>
    <property name="serviceClass"
      value="com.springinaction.chapter08.CitationService">
    </property>
    <property name="namespace"
      value="http://localhost:8080/SpringInAction/ws/citation">
    </property>
  </bean>


xfire.serviceFactory及xfire這兩個被reference的bean是由XFire所提供,import時會載入
接下來要設定Spring MVC DispatcherServlet的部份,請看以下web.xml的部份
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  <servlet>
    <servlet-name>citation</servlet-name>
    <servlet-class>
      org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>
        /WEB-INF/classes/com/springinaction/chapter08/ApplicationContext.xml
      </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  
  <servlet-mapping>
    <servlet-name>citation</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>


由於利用DispatcherServlet在Spring設定中要有相對應的url mapping,設定如下
1
2
3
4
5
6
7
8
9
  <!-- DispatchServlet mapping   -->
  <bean id="urlMapping"
    class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
      <props>
        <prop key="/ws/citation">citationService.xfire</prop>
      </props>
    </property>
  </bean>


完成後可以來測試一下這個Web Service是否成功部署了,開啟IE直接打入http://localhost:8080/SpringInAction/ws/citation?wsdl


reply to postreply to post
☆只要努力就有希望☆
話題樹型展開
人氣 標題 作者 字數 發文時間
4387 Spring Remote Services part2 Web services using SOAP uxa 2403 2007-12-14 14:13
4036 Re:Spring Remote Services part2 Web services using SOAP uxa 1024 2007-12-17 15:24
2228 Re:Spring Remote Services part2 Web services using SOAP chih0812 284 2009-06-16 15:38
2439 Re:Spring Remote Services part2 Web services using SOAP chih0812 1424 2009-06-16 17:59
» JWorld@TW »  Java Application Framework » Spring

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8