刚开始接触 spring webservice 听说是contact-first 想尝尝鲜 不料出错了. 以下是我的代码
public class WebServiceClient extends WebServiceGatewaySupport {
//private static String soapActionPrefix = "http://tempuri.org/";
private Resource request; public void setRequest(Resource request) {
this.request = request;
}
public void getWeather()throws IOException{
//replaceCityName(city);
Source requestSource = new ResourceSource(request);
StringResult result = new StringResult();
System.out.println(requestSource);
System.out.println(getWebServiceTemplate().getDefaultUri());
getWebServiceTemplate().sendSourceAndReceiveToResult(requestSource, result);
System.out.println(result);
}
public static void main(String[] args){
// new WebServiceClient().newMethod("成都");
ApplicationContext applicationContext =
new ClassPathXmlApplicationContext("applicationContext.xml", WebServiceClient.class);
WebServiceClient webServiceClient = (WebServiceClient) applicationContext.getBean("webServiceClient");
try {
webServiceClient.getWeather();
} catch (IOException ex) {
ex.printStackTrace();
}
}
这个是applicationContext.xml 代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="webServiceClient"
class="com.mathew.gwt.springws.WebServiceClient">
<property name="request" value="classpath:com/mathew/gwt/springws/weather.xml"/>
<property name="defaultUri" value="http://www.webxml.com.cn/WebServices/WeatherWebService.asmx" />
</bean>
</beans>
以下是XML代码<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getWeatherbyCityName xmlns="http://WebXml.com.cn/">
<theCityName>成都</theCityName>
</getWeatherbyCityName>
</soap:Body>
</soap:Envelope>大家帮帮忙! 谢谢了
public class WebServiceClient extends WebServiceGatewaySupport {
//private static String soapActionPrefix = "http://tempuri.org/";
private Resource request; public void setRequest(Resource request) {
this.request = request;
}
public void getWeather()throws IOException{
//replaceCityName(city);
Source requestSource = new ResourceSource(request);
StringResult result = new StringResult();
System.out.println(requestSource);
System.out.println(getWebServiceTemplate().getDefaultUri());
getWebServiceTemplate().sendSourceAndReceiveToResult(requestSource, result);
System.out.println(result);
}
public static void main(String[] args){
// new WebServiceClient().newMethod("成都");
ApplicationContext applicationContext =
new ClassPathXmlApplicationContext("applicationContext.xml", WebServiceClient.class);
WebServiceClient webServiceClient = (WebServiceClient) applicationContext.getBean("webServiceClient");
try {
webServiceClient.getWeather();
} catch (IOException ex) {
ex.printStackTrace();
}
}
这个是applicationContext.xml 代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="webServiceClient"
class="com.mathew.gwt.springws.WebServiceClient">
<property name="request" value="classpath:com/mathew/gwt/springws/weather.xml"/>
<property name="defaultUri" value="http://www.webxml.com.cn/WebServices/WeatherWebService.asmx" />
</bean>
</beans>
以下是XML代码<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getWeatherbyCityName xmlns="http://WebXml.com.cn/">
<theCityName>成都</theCityName>
</getWeatherbyCityName>
</soap:Body>
</soap:Envelope>大家帮帮忙! 谢谢了
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货