【发布时间】: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 并且从不放置策略语句)。所以我的问题是:
- GlassFish 为什么坚持添加策略?有什么办法可以压制他们?
- 为什么 Visual Studio 无法通过策略使用 WSDL?
【问题讨论】:
-
您如何使用 WSDL? “添加服务参考”?
-
是 - “添加服务引用”并指向 WSDL 的 URL。
标签: wcf web-services glassfish