无法使用 GlassFish 从 .NET 生成的 WSDL

发布于 2024-10-06 10:14:57 字数 3135 浏览 1 评论 0原文

我正在尝试向 Visual Studio 中的 C# 应用程序添加 Web 服务引用。该 Web 服务托管在 Sun 的 GlassFish 服务器上。不幸的是,当我尝试添加服务引用时,Visual Studio 会生成以下警告:

Custom tool warning: The following Policy Assertions were not Imported:
  XPath://wsdl:definitions/wsdl:binding[@name='SecurityWebServicePortBinding']/wsdl:operation[@name='RegisterUser']
  Assertions:
    <wsat:ATAlwaysCapability xmlns:wsat='http://schemas.xmlsoap.org/ws/2004/10/wsat'>..</wsat:ATAlwaysCapability>

显然它无法理解 GlassFish 服务器发布的 WSDL 中的策略断言。以下是 WSDL 的摘录:

<?xml version='1.0' encoding='UTF-8'?>
<definitions
    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
    xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy"
    xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tns="http://test/securityservice.wsdl"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    targetNamespace="http://test/securityservice.wsdl"
    name="SecurityService">

    <wsp:Policy xmlns:wsat="http://schemas.xmlsoap.org/ws/2004/10/wsat" wsu:Id="SecurityWebServicePortBinding_AuthenticateUser_WSAT_Policy">
        <wsat:ATAlwaysCapability />
        <wsat:ATAssertion xmlns:ns1="http://schemas.xmlsoap.org/ws/2002/12/policy" wsp:Optional="true" ns1:Optional="true" />
    </wsp:Policy>

    <wsp:Policy xmlns:wsat="http://schemas.xmlsoap.org/ws/2004/10/wsat" wsu:Id="SecurityWebServicePortBinding_RegisterUser_WSAT_Policy">
        <wsat:ATAlwaysCapability />
        <wsat:ATAssertion xmlns:ns2="http://schemas.xmlsoap.org/ws/2002/12/policy" wsp:Optional="true" ns2:Optional="true" />
    </wsp:Policy>

    ...

    <binding name="SecurityWebServicePortBinding" type="tns:SecurityWebService">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
        <operation name="RegisterUser">
            <wsp:PolicyReference URI="#SecurityWebServicePortBinding_RegisterUser_WSAT_Policy" />
            <soap:operation soapAction="RegisterUser" />
            <input>
                <wsp:PolicyReference URI="#SecurityWebServicePortBinding_RegisterUser_WSAT_Policy" />
                <soap:body use="literal" />
            </input>
            <output>
                <wsp:PolicyReference URI="#SecurityWebServicePortBinding_RegisterUser_WSAT_Policy" />
                <soap:body use="literal" />
            </output>
            <fault name="UsernameExistsException">
                <soap:fault name="UsernameExistsException" use="literal" />
            </fault>
        </operation>
    </binding>

    ...

</definitions>

如果我从 WSDL 中删除所有策略元素,Visual Studio 就能够毫无问题地使用该服务(事实上,之前我曾经手动编写 WSDL,并且从不放置策略语句)。所以我的问题是:

  1. 为什么 GlassFish 坚持添加这些策略?有什么办法可以压制他们吗?
  2. 为什么 Visual Studio 无法通过策略使用 WSDL?

I am trying to add a web service reference to my C# application in Visual Studio. The web service is hosted on Sun's GlassFish server. Unfortunately Visual Studio produces the following warning when I try to add the service reference:

Custom tool warning: The following Policy Assertions were not Imported:
  XPath://wsdl:definitions/wsdl:binding[@name='SecurityWebServicePortBinding']/wsdl:operation[@name='RegisterUser']
  Assertions:
    <wsat:ATAlwaysCapability xmlns:wsat='http://schemas.xmlsoap.org/ws/2004/10/wsat'>..</wsat:ATAlwaysCapability>

Apparently it cannot understand policy assertions in the WSDL published by the GlassFish server. Here's an excerpt from the WSDL:

<?xml version='1.0' encoding='UTF-8'?>
<definitions
    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
    xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy"
    xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tns="http://test/securityservice.wsdl"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    targetNamespace="http://test/securityservice.wsdl"
    name="SecurityService">

    <wsp:Policy xmlns:wsat="http://schemas.xmlsoap.org/ws/2004/10/wsat" wsu:Id="SecurityWebServicePortBinding_AuthenticateUser_WSAT_Policy">
        <wsat:ATAlwaysCapability />
        <wsat:ATAssertion xmlns:ns1="http://schemas.xmlsoap.org/ws/2002/12/policy" wsp:Optional="true" ns1:Optional="true" />
    </wsp:Policy>

    <wsp:Policy xmlns:wsat="http://schemas.xmlsoap.org/ws/2004/10/wsat" wsu:Id="SecurityWebServicePortBinding_RegisterUser_WSAT_Policy">
        <wsat:ATAlwaysCapability />
        <wsat:ATAssertion xmlns:ns2="http://schemas.xmlsoap.org/ws/2002/12/policy" wsp:Optional="true" ns2:Optional="true" />
    </wsp:Policy>

    ...

    <binding name="SecurityWebServicePortBinding" type="tns:SecurityWebService">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
        <operation name="RegisterUser">
            <wsp:PolicyReference URI="#SecurityWebServicePortBinding_RegisterUser_WSAT_Policy" />
            <soap:operation soapAction="RegisterUser" />
            <input>
                <wsp:PolicyReference URI="#SecurityWebServicePortBinding_RegisterUser_WSAT_Policy" />
                <soap:body use="literal" />
            </input>
            <output>
                <wsp:PolicyReference URI="#SecurityWebServicePortBinding_RegisterUser_WSAT_Policy" />
                <soap:body use="literal" />
            </output>
            <fault name="UsernameExistsException">
                <soap:fault name="UsernameExistsException" use="literal" />
            </fault>
        </operation>
    </binding>

    ...

</definitions>

If I remove all the policy elements from the WSDL, Visual Studio is able to consume the service without any problems (in fact earlier I used to write the WSDL by hand and never put the policy statements). So my questions are:

  1. Why is GlassFish insisting on adding the policies? Is there any way to suppress them?
  2. Why is Visual Studio not able to consume the WSDL with the policies?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月静好 2024-10-13 10:14:57

ws-AT(原子事务)似乎是 WCF 不知道的 SOAP 规范的一部分。
这里有一些信息 - http://schemas.xmlsoap.org/ws/2004/ 10/wsat/

更新:实际上,WCF 知道 ws-AT 规范,但并不完全支持它(http://schemas.xmlsoap.org/ws/2004/10/wsat/)。我想这是因为 WCF 有使用 OleTransactions 的替代方案。

ws-AT (Atomic Transactions) seems to be part of the SOAP specification which WCF does not know about.
There is some information here - http://schemas.xmlsoap.org/ws/2004/10/wsat/

Update: Actually WCF is aware of the ws-AT spec, but doesn't support it fully (http://schemas.xmlsoap.org/ws/2004/10/wsat/). I suppose this is because WCF has alternatives which use OleTransactions.

滴情不沾 2024-10-13 10:14:57

好的,我明白为什么 GlassFish 添加 ws-AT 策略了。我的 Web 服务是使用 EJB 生成的(见下文):

@Stateless
@WebService
public class SecurityWebService {
    ...
}

由于无状态 EJB 方法的默认事务属性是必需的,GlassFish 也使 Web 服务方法具有事务性(请参阅 此处 了解详细信息)。这不是我想要的行为,但事实就是如此!

Ok, I figured out why GlassFish is adding the ws-AT policies. My web service is being generated using an EJB (see below):

@Stateless
@WebService
public class SecurityWebService {
    ...
}

Since the default transaction attribute for a stateless EJB method is REQUIRED, GlassFish is making the web service method transactional too (see here for details). Not the behavior I want, but that's how it is!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文