Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java WSDL操作中的soapAction属性为空_Java_Spring_Web Services_Soap_Wsdl - Fatal编程技术网

Java WSDL操作中的soapAction属性为空

Java WSDL操作中的soapAction属性为空,java,spring,web-services,soap,wsdl,Java,Spring,Web Services,Soap,Wsdl,存在具有以下WSDL的web服务: <?xml version="1.0" encoding="UTF-8" standalone="no"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch="http://fer2.klab/notify" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://

存在具有以下WSDL的web服务:

<?xml version="1.0" encoding="UTF-8" standalone="no"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch="http://fer2.klab/notify" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://fer2.klab/notify" targetNamespace="http://fer2.klab/notify">
  <wsdl:types>
    <xs:schema xmlns:er="http://fer2.klab/notify" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://fer2.klab/notify">
    <xs:element name="ServiceRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element maxOccurs="1" minOccurs="1" name="HL7message" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="ServiceResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element maxOccurs="1" minOccurs="1" name="response" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>
  </wsdl:types>
  <wsdl:message name="ServiceResponse">
    <wsdl:part element="tns:ServiceResponse" name="ServiceResponse">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="ServiceRequest">
    <wsdl:part element="tns:ServiceRequest" name="ServiceRequest">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="NotifyPort">
    <wsdl:operation name="Service">
      <wsdl:input message="tns:ServiceRequest" name="ServiceRequest">
    </wsdl:input>
      <wsdl:output message="tns:ServiceResponse" name="ServiceResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="NotifyPortSoap11" type="tns:NotifyPort">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="Service">
      <soap:operation soapAction=""/>
      <wsdl:input name="ServiceRequest">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="ServiceResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="NotifyPortService">
    <wsdl:port binding="tns:NotifyPortSoap11" name="NotifyPortSoap11">
      <soap:address location="http://192.168.1.101:8080/fer2-0.0.1/ws"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>
dispatcher-servlet.xml:

<bean id="notify" name="notify" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
    <!--<property name="createSoap12Binding" value="true" />-->
    <property name="portTypeName" value="NotifyPort" />
    <property name="locationUri" value="/ws" />
    <property name="schema">
        <bean class="org.springframework.xml.xsd.SimpleXsdSchema">
            <property name="xsd" value="notify.xsd" />
        </bean>
    </property>
    <property name="targetNamespace" value="http://fer2.klab/notify" />
    <!--<property name="soapActions">-->
        <!--<props>-->
            <!--<prop key="ServiceRequest">http://fer2.klab/notify/ServiceRequest"</prop>-->
        <!--</props>-->
    <!--</property>-->
</bean>
导致记录以下错误:

 org.springframework.ws.server.EndpointNotFound- No endpoint mapping found for [SaajSoapMessage {http://fer2.klab/notify}ServiceRequest]

soap:operation
元素的
soapAction
属性是将包含在HTTP请求消息中的值,如:

POST /StockQuote HTTP/1.1
Content-Type: text/xml; charset="utf-8"
Content-Length: nnnn
SOAPAction: "http://electrocommerce.org/abc#MyMessage"
如中所述,该值仅指示将调用哪个操作的意图,web服务框架在创建存根时通常不使用该值


一种常见的模式是将其设置为空字符串,因为在
中,问题最终得到了解决

WSDL是自动生成的,并且是静态的

端点更改如下(此处的要点是
@Action
注释):

dispatcherservlet.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"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:sws="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <sws:annotation-driven />

    <bean id="notify" name="notify" class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition">
        <property name="wsdl" value="notify.wsdl" />
    </bean>

    <context:component-scan base-package="klab.fer2"/>

</beans>

对我来说,它只起作用(spring boot应用程序):

wsdl11Definition.setSoapActions(soapActions)

public class WebServiceConfig extends WsConfigurerAdapter {

@Bean(name = "someService")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema schema) {
    DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
    ....

    Properties soapActions = new Properties();
    for (Method method : endpointController.class.getMethods() ) {
        soapActions.setProperty(method.getName(), Const.NAMESPACE_URI + "/#" + method.getName());
    }
    wsdl11Definition.setSoapActions(soapActions);

    return wsdl11Definition;
}

您可以使用Metro或Axis实现来构建基于SOAP的web服务。这里有一些例子
POST /StockQuote HTTP/1.1
Content-Type: text/xml; charset="utf-8"
Content-Length: nnnn
SOAPAction: "http://electrocommerce.org/abc#MyMessage"
@Endpoint
public class NotifyEndPoint {

    private static final String NAMESPACE_URL = "http://fer2.klab/notify";

    @Autowired
    MainController mainController;

    @PayloadRoot(namespace = NAMESPACE_URL, localPart = "ServiceRequest")
    @Action("http://fer2.klab/notify/ServiceRequest")
//    @ResponsePayload
    public void send(@RequestPayload ServiceRequest hlMessage) {
        System.out.println("notify method");
        mainController.notify(null, "", hlMessage.getHL7Message());
    }

}
<?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:context="http://www.springframework.org/schema/context"
       xmlns:sws="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <sws:annotation-driven />

    <bean id="notify" name="notify" class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition">
        <property name="wsdl" value="notify.wsdl" />
    </bean>

    <context:component-scan base-package="klab.fer2"/>

</beans>
public class WebServiceConfig extends WsConfigurerAdapter {

@Bean(name = "someService")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema schema) {
    DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
    ....

    Properties soapActions = new Properties();
    for (Method method : endpointController.class.getMethods() ) {
        soapActions.setProperty(method.getName(), Const.NAMESPACE_URI + "/#" + method.getName());
    }
    wsdl11Definition.setSoapActions(soapActions);

    return wsdl11Definition;
}