公开WebService方法问题

时间:2016-06-06 01:02:05

标签: java web-services jax-ws

我不明白为什么我公开了Web服务方法,根据JAX-WS规范(根据我的理解)不应该这样。

我创建了一个带有隐式SEI的简单测试Web服务:

@WebService
@SOAPBinding(style = Style.RPC)
public interface TestServiceSEI 
{
    public String helloTest();
    @WebMethod public String helloTest2();
}

目标是在WebService中公开helloTest()而不是,并在WebService中公开helloTest2()。然后我实现了这个SIB:

我特意省略endpointInterface参数来制作这个隐式SEI。我的理解是,使用隐式SEI,为了公开Web服务,我必须使用@WebMethod注释,任何未在隐式SEI中使用@WebMethod注释的方法都不应该在WebService中公开?

因此:

@WebService 
public class TestServiceSIB implements TestServiceSEI
{
    @Override
    //this method should not be exposed? 
    public String helloTest() 
    {
        return "HELLO WORLD";
    }

    //only this method should be exposed     
    @Override
    public String helloTest2()
    {
        return "HELLO WEB SERVICE";
    }   
}

发布WebService时:

public static void main(String[] args) 
{
    Endpoint.publish("http://localhost:9876/ws", new TestServiceSIB());
}

尽管如此,我看到在WebService操作中公开了所有方法:

<operation name="helloTest">
    <soap:operation soapAction=""/>
        <input>
            <soap:body use="literal"/>
        </input>
        <output>
           <soap:body use="literal"/>
        </output>
    </operation>
<operation name="helloTest2">
    <soap:operation soapAction=""/>
        <input>
           <soap:body use="literal"/>
        </input>
        <output>
           <soap:body use="literal"/>
        </output>
</operation>

无论我尝试什么,我总是在WebService中显示所有方法,但根据JAX-WS规范方法仅在我试图避免的特定情况下暴露,但它们仍会暴露。我试图遵循规范并隐藏某些方法,但他们一直在显示。

有人可以解释为什么我不断暴露helloTest()吗?

感谢。

1 个答案:

答案 0 :(得分:0)

您可以尝试注释您不想公开的公共方法 使用注释

@WebMethod(exclude=true)
相关问题