Visual Studio 2017 Add Service Reference создает пустой клиент из WSDL с 2 файлами XSD - PullRequest
0 голосов
/ 06 июня 2019

У меня есть свой собственный веб-сервис SOAP с WSDL.Я пытаюсь использовать этот веб-сервис из проекта C #.Однако при добавлении ссылки на службу и вводе адреса WSDL служба обнаруживается, но при нажатии «ОК» Visual Studio 2017 выдает предупреждения и не создает клиента из WSDL.Я попытался с помощью svcutil.exe и он выводит клиент, но он не создает другие файлы, которые производит Visual Studio.В любом случае должна быть возможность заставить Visual Studio сгенерировать клиентский класс для использования веб-службы.

Когда я пытаюсь добавить веб-ссылку из того же WSDL, в Visual Studio нет никаких проблем.Однако я хотел бы использовать ссылку на службу, поскольку я понял, что это более новый подход.

Я пробовал использовать другие файлы WSDL веб-сервисов SOAP, из которых Visual Studio 2017 может создать рабочую ссылку на службу.,Разница между неработающим веб-сервисом и работающим состоит в том, что у того, который работает, есть WSDL, который включает в себя один файл XSD, тогда как у того, который не работает, есть WSDL, который импортирует файл XSD (XSD1), который включает в себя другой файл XSD.(XSD2).Типы были разделены на два отдельных файла XSD, потому что некоторые типы используются в нескольких сервисах.

Visual Studio 2017 - библиотека классов .NET Framework Project Add Service Reference работает с WSDL одного веб-сервиса, который импортирует файл XSD.

Добавление справочника услуг не работает с веб-сервисом, в который WSDL-файл импортирует XSD, который включает в себя другой XSD.Добавление веб-ссылки из того же WSDL приводит к созданию клиента 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:

<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
...