您面临的问题是网络服务位于http://www.dneonline.com/calculator.asmx http://www.dneonline.com/calculator.asmx期望一个SOAPAction
标头。由于您没有提供服务,因此该服务不知道如何路由请求。
您正在学习的教程不需要SOAPAction
header 来进行路由。
如果你看看如何Add
操作被指定在WSDL http://www.dneonline.com/calculator.asmx?wsdl,你会发现的期望值SOAPAction
那里有标题。该服务提供的所有其他操作也是如此。
<wsdl:operation name="Add">
<soap:operation soapAction="http://tempuri.org/Add" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
假设你的SoapConnector
类与中的类相同教程 https://howtodoinjava.com/spring-boot/spring-soap-client-webservicetemplate/你可以删除String url
作为输入callWebservice
方法,因为它已经通过client.setDefaultUri("http://www.dneonline.com/calculator.asmx");
in the SoapConnector
豆。相反,添加String soapAction
作为输入参数,为您提供以下内容
public class SOAPConnector extends WebServiceGatewaySupport {
public Object callWebService(Object request, String soapAction){
return getWebServiceTemplate().marshalSendAndReceive(url, new SoapActionCallback(soapAction));
}
}
然后,删除wsdlurl
作为输入soapConnector.callWebService
(无论如何这是错误的)并添加soapHeader
您想要使用的操作的值,留给您这个
@Bean
CommandLineRunner lookup(SoapConnector soapConnector) {
return args -> {
Integer a = 10;
Integer b = 20;
if(args.length>0){
a = Integer.parseInt(args[0]);
b = Integer.parseInt(args[1]);
}
Add add = new Add();
add.setIntA(a);
add.setIntB(b);
AddResponse addRes = (AddResponse) soapConnector.callWebService(add, "http://tempuri.org/Add");
System.out.println("Got Response As below ========= : ");
System.out.println("Added result : "+addRes.getAddResult());
};
}
当然,如果你想使用除此之外的其他操作Add
您必须调整此解决方案以使其通用。