使用spring和定义xml发送soap请求



我试图连接到一个服务与spring运行soap操作定义为

https://services.domain.getuserbyid

这是我的代码,但它告诉我前缀"tem"没有被绑定。假设我的webServiceTemplate正在正确加载,我如何才能正确定义这个前缀,以便我可以发送这个soap消息?如果需要更多的信息,请告诉我。

import java.io.StringReader;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.client.core.WebServiceMessageCallback;
import org.springframework.ws.client.core.WebServiceTemplate;
import org.springframework.ws.soap.SoapMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.*;
@TestExecutionListeners( { DependencyInjectionTestExecutionListener.class })
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"spring-ws.xml"})
public class TestWebServiceClient {
    private static final String ENVELOPE_PREFIX = "soap";
    private static final String MESSAGE =  
                "<tem:GetUserByID> " + 
                    "<tem:samAccountName>name</tem:samAccountName> " + 
                 "</tem:GetUserByID> " ; 
    @Autowired
    private WebServiceTemplate webServiceTemplate;
    @Test
    // send to the configured default URI
    public void simpleSendAndReceive() {
        StreamSource source = new StreamSource(new StringReader(MESSAGE));
        StreamResult result = new StreamResult(System.out);

        //webServiceTemplate.sendSourceAndReceiveToResult(source, result);
        webServiceTemplate.marshalSendAndReceive(webServiceTemplate.sendSourceAndReceiveToResult(source, result), new WebServiceMessageCallback() {  
                public void doWithMessage(WebServiceMessage message) {
                ((SoapMessage)message).setSoapAction("https://services.domain.getuserbyid");
            }});
    }
    public void setWebServiceTemplate(WebServiceTemplate webServiceTemplate) {
        this.webServiceTemplate = webServiceTemplate;
    }
    public WebServiceTemplate getWebServiceTemplate() {
        return this.webServiceTemplate;
    }
}

我的spring应用程序上下文文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:oxm="http://www.springframework.org/schema/oxm"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
  xmlns:mongo="http://www.springframework.org/schema/data/mongo"
   xmlns:util="http://www.springframework.org/schema/util"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.2.xsd
    http://www.springframework.org/schema/data/mongo
    http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
    http://www.directwebremoting.org/schema/spring-dwr
    http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util.xsd
    http://www.springframework.org/schema/oxm 
    http://www.springframework.org/schema/oxm/spring-oxm.xsd">
    <context:component-scan base-package="com.domain"/>
    <context:annotation-config />  
    <bean id="soapMessageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
        <property name="soapVersion">
            <util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12"/>
        </property>
    </bean>
    <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
        <constructor-arg ref="soapMessageFactory"/>
        <property name="defaultUri" value="https://domain.com/Service.svc?WSDL"/>
    </bean>      
</beans>

算出来了,需要添加到我的XML

<tem:GetUserByID xmlns:tem="http://domain/GetUserByIDResponse/">
      <tem:samAccountName>name</tem:samAccountName>
</tem:GetUserByID> 

相关内容

  • 没有找到相关文章

最新更新