我有自己的带有WSDL的SOAP Web服务。我正在尝试从C#项目中使用此Web服务。但是,当我添加服务引用并输入WSDL地址时,会找到该服务,但是当单击“确定”时,Visual Studio 2017会遇到警告,并且不会从WSDL创建客户端。 我尝试使用svcutil.exe,它会输出客户端,但不会创建Visual Studio生成的其他文件。无论哪种方式,都应该可以使Visual Studio生成客户端类以使用Web服务。
当我尝试从同一WSDL添加Web引用时,在Visual Studio中没有问题。但是,我想使用服务参考,因为我知道这是一种较新的方法。
我尝试使用其他SOAP Web服务WSDL文件,Visual Studio 2017可以从中创建有效的服务参考。 Web服务无法正常工作与正常工作之间的区别在于,可以正常工作的Web服务具有包含单个XSD文件的WSDL,而不能正常工作的网络服务具有导入包括另一个XSD文件的XSD文件(XSD1)的WSDL。 (XSD2)。 这些类型已拆分为两个单独的XSD文件,因为其中一些类型可在多个服务中使用。
Visual Studio 2017-类库.NET框架项目 “添加服务参考”与一个Web服务的WSDL配合使用,该服务会导入XSD文件。
添加服务参考不适用于webservice,该Webservice的WSDL文件导入了包含另一个XSD的XSD。 从同一WSDL添加Web引用会导致Visual Studio 2017生成客户端。
WSDL:
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" 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:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://[...]/services/helloworld/v1.0" xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" name="HelloWorld" targetNamespace="http://[...]/services/helloworld/v1.0">
<wsdl:import location="http://[local JBoss Fuse server]/services/HelloWorld/?wsdl=WSPolicy.wsdl" namespace="http://[...]/services/helloworld/v1.0"> </wsdl:import>
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 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:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://[...]/services/helloworld/v1.0" xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<xsd:import namespace="http://[...]/services/helloworld/v1.0" schemaLocation="http://[local JBoss Fuse Server]/services/HelloWorld/?xsd=HelloWorld.xsd"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="PingResponse">
<wsdl:part element="tns:PingSvar" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="GetAliveWithParameterResponse">
<wsdl:part element="tns:GetAliveWithParameterResponse" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="PingRequest">
<wsdl:part element="tns:Ping" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="GetAliveWithParameterRequest">
<wsdl:part element="tns:GetAliveWithParameter" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="ServiceException">
<wsdl:part element="tns:ServiceFaultDetailer" name="fault"> </wsdl:part>
</wsdl:message>
<wsdl:portType name="HelloWorldPortType">
<wsdl:operation name="GetAliveWithParameter">
<wsdl:input message="tns:GetAliveWithParameterRequest">
<wsp:PolicyReference URI="#AsymmetricX509TokensWithUntPolicy"/>
</wsdl:input>
<wsdl:output message="tns:GetAliveWithParameterResponse"> </wsdl:output>
<wsdl:fault message="tns:ServiceException" name="ServiceException"> </wsdl:fault>
</wsdl:operation>
<wsdl:operation name="Ping">
<wsdl:input message="tns:PingRequest"> </wsdl:input>
<wsdl:output message="tns:PingResponse"> </wsdl:output>
<wsdl:fault message="tns:ServiceException" name="ServiceException"> </wsdl:fault>
</wsdl:operation>
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
</jaxws:bindings>
</wsdl:portType>
<wsdl:binding name="HelloWorldSoapBinding" type="tns:HelloWorldPortType">
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Ping">
<soap12:operation soapAction="http://[...]/services/helloworld/v1.0/Ping" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetAliveWithParameter">
<soap12:operation soapAction="http://[...]/services/helloworld/v1.0/GetAliveWithParameter" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloWorld">
<wsdl:port binding="tns:HelloWorldSoapBinding" name="HelloWorldPort">
<soap12:address location="http://[local JBoss Fuse Server]/services/HelloWorld/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
WSPolicy.wsdl:
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" xmlns="http://schemas.xmlsoap.org/wsdl/" name="Policies" targetNamespace="http://policies.test.policy.ws.xml.sun.com/">
<wsp:Policy wsu:Id="AsymmetricX509TokensWithUntPolicy">
<wsp:ExactlyOne>
<wsp:All>
<sp:SupportingTokens>
<wsp:Policy>
<sp:UsernameToken sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
<wsp:Policy>
<sp:WssUsernameToken10/>
</wsp:Policy>
</sp:UsernameToken>
</wsp:Policy>
</sp:SupportingTokens>
<sp:AsymmetricBinding>
<wsp:Policy>
<sp:InitiatorToken>
<wsp:Policy>
<sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
<wsp:Policy>
<sp:WssX509V3Token10/>
</wsp:Policy>
</sp:X509Token>
</wsp:Policy>
</sp:InitiatorToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic128/>
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Lax/>
</wsp:Policy>
</sp:Layout>
<sp:IncludeTimestamp/>
<sp:ProtectTokens/>
<sp:OnlySignEntireHeadersAndBody/>
</wsp:Policy>
</sp:AsymmetricBinding>
<sp:SignedParts>
<sp:Body/>
<sp:Header Name="Timestamp" Namespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"/>
</sp:SignedParts>
<sp:Wss11>
<wsp:Policy>
<sp:MustSupportRefKeyIdentifier/>
</wsp:Policy>
</sp:Wss11>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
</definitions>
XSD:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://[...]/services/helloworld/v1.0" elementFormDefault="qualified" targetNamespace="http://[...]/services/helloworld/v1.0">
<xs:include schemaLocation="http://[local JBoss Fuse Server]/services/HelloWorld/?xsd=CommonTypes.xsd"/>
<xs:element name="GetAliveWithParameter">
<xs:complexType>
<xs:sequence>
<xs:element name="Modtager" type="tns:Modtager"/>
<xs:element name="InputMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetAliveWithParameterResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="Modtager" type="tns:Modtager"/>
<xs:element name="TestResult" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="ExtendedValidationResult">
<xs:sequence>
<xs:element minOccurs="0" name="ErrorCount" type="xs:int"/>
<xs:element minOccurs="0" name="Message" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="ValidationErrors" nillable="true" type="tns:ArrayOfExtendedValidationError"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ExtendedValidationResult" nillable="true" type="tns:ExtendedValidationResult"/>
<xs:complexType name="ArrayOfExtendedValidationError">
<xs:sequence>
<xs:element minOccurs="0" name="ExtendedValidationError" nillable="true" type="tns:ExtendedValidationError"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfExtendedValidationError" nillable="true" type="tns:ArrayOfExtendedValidationError"/>
<xs:complexType name="ExtendedValidationError">
<xs:sequence>
<xs:element minOccurs="0" name="ErrorHoldId" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="ErrorLocation" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="ErrorMessage" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="ErrorPersonId" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="ErrorType" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ExtendedValidationError" nillable="true" type="tns:ExtendedValidationError"/>
</xs:schema>
XSD CommonTypes:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="Ping">
<xs:complexType>
<xs:sequence/>
</xs:complexType>
</xs:element>
<xs:element name="PingSvar">
<xs:complexType>
<xs:sequence>
<xs:element name="PingResult" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="RestrictedStringType">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9a-zA-Z_\-]+"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="Modtager">
<xs:sequence>
<xs:element name="ModtagerSystemID" type="RestrictedStringType"/>
<xs:element name="ModtagerSystemTransaktionsID" type="RestrictedStringType"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ServiceFaultDetailer">
<xs:complexType>
<xs:sequence>
<xs:element name="FejlKode" type="xs:string"/>
<xs:element name="Fejlmeddelelse" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
尝试添加服务参考时,来自Visual Studio 2017的错误消息:
1。
Severity Code Description Project File Line Suppression State
Warning Custom tool warning: The optional WSDL extension element 'bindings' from namespace 'http://java.sun.com/xml/ns/jaxws' was not handled.
XPath: //wsdl:definitions[@targetNamespace='http://[...]/services/helloworld/v1.0']/wsdl:portType[@name='HelloWorldPortType'] ClassLibrary3 C:\Users\[...]\Documents\Visual Studio 2017\Projects\ClassLibrary3\Connected Services\HelloWorldLocal\Reference.svcmap 1
2。
Severity Code Description Project File Line Suppression State
Warning Custom tool warning: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://[...]/services/helloworld/v1.0']/wsdl:binding[@name='HelloWorldSoapBinding']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://[...]/services/helloworld/v1.0']/wsdl:service[@name='HelloWorld']/wsdl:port[@name='HelloWorldPort'] ClassLibrary3 C:\Users\[...]\Documents\Visual Studio 2017\Projects\ClassLibrary3\Connected Services\HelloWorldLocal\Reference.svcmap 1
3。
Severity Code Description Project File Line Suppression State
Warning Custom tool warning: The optional WSDL extension element 'PolicyReference' from namespace 'http://www.w3.org/ns/ws-policy' was not handled.
XPath: //wsdl:definitions[@targetNamespace=''] ClassLibrary3 C:\Users\[...]\Documents\Visual Studio 2017\Projects\ClassLibrary3\Connected Services\HelloWorldLocal\Reference.svcmap 1
4。
Severity Code Description Project File Line Suppression State
Warning Custom tool warning: Cannot import wsdl:binding
Detail: The given key was not present in the dictionary.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://[...]/services/helloworld/v1.0']/wsdl:binding[@name='HelloWorldSoapBinding'] ClassLibrary3 C:\Users\[...]\Documents\Visual Studio 2017\Projects\ClassLibrary3\Connected Services\HelloWorldLocal\Reference.svcmap 1