为什么这个简单的Web服务(部署到weblogic 11g)收到此错误:“wsa:MessageAddressingHeaderRequired”?

时间:2012-12-21 23:48:33

标签: web-services weblogic jax-ws

问题: 的 我已经多次重新创建并部署了这个非常简单的jax-ws webservice(见下文)。 但是,我无法让这个简单的Web服务应用程序运行!

也就是说,当我提交简单的SOAP请求时(请参阅下面的“服务请求”),我收到以下错误:“ wsa:MessageAddressingHeaderRequired

问题: 的 导致此错误的原因是什么:“wsa:MessageAddressingHeaderRequired”?

更多信息,以下......

以下是实施类......

package aaa.bbb.ccc;

import ccc.bbb.aaa.testws.ObjectFactory;
import ccc.bbb.aaa.testws.ResponseType;
import javax.jws.WebService;

@WebService(serviceName = "testws", portName = "testwsSOAP", endpointInterface = "ccc.bbb.aaa.testws.Testws", targetNamespace = "http://aaa.bbb.ccc/testws/", wsdlLocation = "WEB-INF/wsdl/testws.wsdl")
public class testws
{
    public ccc.bbb.aaa.testws.ResponseType multiplyOperation(ccc.bbb.aaa.testws.RequestType request)
    {
        Integer value1 = new Integer(request.getParmValue1());
        Integer value2 = new Integer(request.getParmValue2());
        Integer product = value1 * value2;
        ObjectFactory factory = new ObjectFactory();
        ResponseType response = factory.createResponseType();
        response.setValue1(value1.toString());
        response.setValue2(value2.toString());
        response.setProduct(product.toString());
        return response;
    }
}

这是WSDL ......

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tns="http://aaa.bbb.ccc/testws/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="testws"
    targetNamespace="http://aaa.bbb.ccc/testws/" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp1="http://www.w3.org/ns/ws-policy" xmlns:fi="http://java.sun.com/xml/ns/wsit/2006/09/policy/fastinfoset/service" xmlns:tcp="http://java.sun.com/xml/ns/wsit/2006/09/policy/soaptcp/service" xmlns:wsaw="http://www.w3.org/2005/08/addressing" xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm/policy" xmlns:sunrm="http://sun.com/2006/03/rm" xmlns:net="http://schemas.microsoft.com/net/2005/02/rm/policy">
    <wsdl:types>
        <xsd:schema targetNamespace="http://aaa.bbb.ccc/testws/"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:Q1="http://aaa.bbb.ccc/testws">
            <xsd:import schemaLocation="testws.xsd"
                namespace="http://aaa.bbb.ccc/testws">
            </xsd:import>
            <xsd:element name="multiplyOperation">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="request"
                            type="Q1:requestType" />
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="multiplyOperationResponse">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="response"
                            type="Q1:responseType" />
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="multiplyOperationRequest">
        <wsdl:part element="tns:multiplyOperation" name="parameters" />
    </wsdl:message>
    <wsdl:message name="multiplyOperationResponse">
        <wsdl:part element="tns:multiplyOperationResponse"
            name="parameters" />
    </wsdl:message>
    <wsdl:portType name="testws">
        <wsdl:operation name="multiplyOperation">
            <wsdl:input message="tns:multiplyOperationRequest" />
            <wsdl:output message="tns:multiplyOperationResponse" />
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="testwsSOAP" type="tns:testws">
     <wsaw:UsingAddressing wsdl:required="true" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"/>

        <soap:binding style="document"
            transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="multiplyOperation">
            <soap:operation
                soapAction="http://aaa.bbb.ccc/testws/multiplyOperation" />
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="testws">
        <wsdl:port binding="tns:testwsSOAP" name="testwsSOAP">
            <soap:address location="http://aaa.bbb.ccc/" />
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

这是XSD ......

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://aaa.bbb.ccc/testws"
    xmlns:tns="http://aaa.bbb.ccc/testws"
    elementFormDefault="qualified">

    <element name="query" type="tns:queryType"></element>

    <complexType name="queryType">
        <choice>
            <element name="request" type="tns:requestType"></element>
            <element name="response" type="tns:responseType"></element>
        </choice>
    </complexType>

    <complexType name="requestType">
        <sequence>
            <element name="parmValue1" type="string"></element>
            <element name="parmValue2" type="string"></element>
        </sequence>
    </complexType>

    <complexType name="responseType">
        <sequence>
            <element name="value1" type="string"></element>
            <element name="value2" type="string"></element>
            <element name="product" type="string"></element>
        </sequence>
    </complexType>
</schema>

以下是测试请求...

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Header />
    <env:Body>
    <multiplyOperation xmlns="http://aaa.bbb.ccc/testws/" xmlns:tes="http://aaa.bbb.ccc/testws">
      <request xmlns="">
        <tes:parmValue1>3</tes:parmValue1>
        <tes:parmValue2>4</tes:parmValue2>
      </request>
    </multiplyOperation>
  </env:Body>
  </env:Envelope>

以下是测试回复......

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Header>
    <FaultDetail xmlns="http://www.w3.org/2005/08/addressing">
      <ProblemHeaderQName>{http://www.w3.org/2005/08/addressing}Action</ProblemHeaderQName>
    </FaultDetail>
  </S:Header>
    <S:Body>
    <SOAP-ENV:Fault xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
      <faultcode xmlns:wsa="http://www.w3.org/2005/08/addressing">wsa:MessageAddressingHeaderRequired</faultcode>
      <faultstring>A required header representing a Message Addressing Property is not present</faultstring>
    </SOAP-ENV:Fault>
  </S:Body>
  </S:Envelope>

这是我用过的Maven构建脚本......

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>aaa.bbb.ccc</groupId>
  <artifactId>testwswaronly</artifactId>
  <packaging>war</packaging>
  <version>1</version>

  <name>testwswaronly</name>
  <url>http://maven.apache.org</url>

  <dependencies>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.sun.xml.ws</groupId>
      <artifactId>webservices-rt</artifactId>
      <version>1.4</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.jvnet.jax-ws-commons</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>2.2</version>
        <executions>
          <execution>
            <goals>
              <goal>wsimport</goal>
            </goals>
            <configuration>
              <wsdlFiles>
                <wsdlFile>testws.wsdl</wsdlFile>
              </wsdlFiles>
              <staleFile>${project.build.directory}/jaxws/stale/testws.stale</staleFile>
            </configuration>
            <id>wsimport-generate-testws</id>
            <phase>generate-sources</phase>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>javax.xml</groupId>
            <artifactId>webservices-api</artifactId>
            <version>1.4</version>
          </dependency>
        </dependencies>
        <configuration>
          <sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport</sourceDestDir>
          <xnocompile>true</xnocompile>
          <verbose>true</verbose>
          <extension>true</extension>
          <catalog>${basedir}/src/jax-ws-catalog.xml</catalog>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
          <webResources>
            <resource>
              <directory>src</directory>
              <targetPath>WEB-INF</targetPath>
              <includes>
                <include>jax-ws-catalog.xml</include>
                <include>wsdl/**</include>
              </includes>
            </resource>
          </webResources>
        </configuration>
      </plugin>
    </plugins>
  </build>
    <properties>
        <netbeans.hint.deploy.server>WebLogic9</netbeans.hint.deploy.server>
    </properties>
</project>

1 个答案:

答案 0 :(得分:1)

您的WSDL包含:

<wsaw:UsingAddressing wsdl:required="true" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"/>

请注意,required属性设置为true。但是您的测试请求不包含任何标题:

<env:Header />

我相信响应的FaultDetail标题会告诉您需要哪个请求标头:

<ProblemHeaderQName>{http://www.w3.org/2005/08/addressing}Action</ProblemHeaderQName>