【问题标题】:Can't consume GlassFish generated WSDL from .NET无法使用来自 .NET 的 GlassFish 生成的 WSDL
【发布时间】:2010-12-03 10:19:37
【问题描述】:

我正在尝试在 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?

【问题讨论】:

  • 您如何使用 WSDL? “添加服务参考”?
  • 是 - “添加服务引用”并指向 WSDL 的 URL。

标签: wcf web-services glassfish


【解决方案1】:

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 导致了这个问题,有没有办法阻止 GlassFish 发出 ws-AT 策略?
【解决方案2】:

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

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

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

【讨论】:

    猜你喜欢
    • 2012-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-07
    相关资源
    最近更新 更多