6
votes

I'm trying to add service reference to my (.NET 4.6) project.
When I choose Add Service Reference and add URL of WSDL I can see it is correctly discovered: enter image description here

I've unchecked Reuse types in all referenced assemblies as shown below: enter image description here

But when I click OK I get three warnings in Error List window:

Warning 1 Custom tool warning: Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.XmlSerializerMessageContractImporter Error: Unable to cast object of type 'System.Xml.Serialization.StructMapping' to type 'System.Xml.Serialization.MembersMapping'. XPath to Error Source: //wsdl:definitions[@targetNamespace='http://bik.pl/cc/big']/wsdl:portType[@name='BIG']

Warning 3 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://bik.pl/cc/big']/wsdl:binding[@name='BIGBinding'] XPath to Error Source: //wsdl:definitions[@targetNamespace='http://bik.pl/cc/big']/wsdl:service[@name='BIG']/wsdl:port[@name='BIG']

Warning 2 Custom tool warning: Cannot import wsdl:binding Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on. XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='http://bik.pl/cc/big']/wsdl:portType[@name='BIG'] XPath to Error Source: //wsdl:definitions[@targetNamespace='http://bik.pl/cc/big']/wsdl:binding[@name='BIGBinding']

I've tried different options while importing, but I get those errors all the time.
I've validated WSDL using www.wsdl-analyzer.com but it shows no error: enter image description here

Here is quality report: https://www.wsdl-analyzer.com/qualityReport/show/1784995829?version=1

SoapUI correctly shows all operations and I'm able to do them from SoapUI, but I need to add reference to my project in Visual Studio.

Below are links to WSDL and XSD:

https://wasstt.infomonitor.pl/39D97477-0709-455f-A7C8-6498B600AC5A/ws/BIG/WEB-INF/wsdl/dluznik.wsdl

https://wasstt.infomonitor.pl/39D97477-0709-455f-A7C8-6498B600AC5A/ws/BIG/WEB-INF/wsdl/dluznik.xsd

How can I import this WSDL into my project? I'm unable to modify structure of that WSDL, so I must use it as it is.

EDIT: I've installed XMLSpy and opened that WSDL in it. After opening I got message saying that WSDL is valid.

4
are there any complex types defined in your wsdl?Ozan Gunceler
@OzanGunceler I've just opened WSDL and XSD and yes, there are complex types (xs:complexType) You can see them in XSDMisiu
@OzanGunceler I've used similar WSDL's in past and they had even more complex objects (types) required and returned by methods. Problem with this WSDL is that I can't import it correctlyMisiu
It appears your first warning is throwing your following two warnings. There is another question with a similar failure that may help you, here , with links in the answer. This would focus around the casting issue displayed in warning 1.vipersassassin
Also, this functions without issue on .Net 4.5 and fails on .Net 4.6. Are you able to change your Target framework to .Net 4.5 and verify this is the source of the issue?vipersassassin

4 Answers

3
votes

Probably the problem has already been solved in a different way (other technology, resignation from the contract), but if you are still interested, the problem is that wsdl.exe don't support circular reference in element definition.

<xs:element name="raport-z-rej-zap">
    <xs:complexType>
    <!-- ... -->
        <xs:element ref="tns:raport-z-rej-zap" minOccurs="0" maxOccurs="unbounded" />
    <!-- ... -->
    </xs:complexType>
</xs:element>

All You need is to define named complex type insted of anonymous:

<xs:element name="raport-z-rej-zap" type="tns:Raport-z-rej-zap">
    <xs:annotation>
        <xs:documentation>Struktura raportow z Rejestru Zapytan (ref. 6.6)</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:complexType name="Raport-z-rej-zap">
    <xs:choice>
        <xs:sequence>
            <xs:element name="naglowek" type="tns:TypNaglowekRaportu" />
            <xs:element name="pytajacy" type="tns:TypDanePodmiotuPytajacego" minOccurs="0" />
            <xs:element name="dane-zap" type="tns:TypDaneZapytaniaZRejZap" minOccurs="0" />
            <xs:element name="uwagi-i-ostrz" type="tns:TypUwagOstrzezen" minOccurs="0" />
            <xs:element name="podmiot" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="dane-podm" type="tns:TypDanePodmiotu" />
                        <xs:element name="tresc-rap" minOccurs="0" maxOccurs="unbounded">
                            <xs:annotation>
                                <xs:documentation>Tresc uprzednio przekazanego raportu</xs:documentation>
                            </xs:annotation>
                            <xs:complexType>
                                <xs:choice>
                                    <xs:element ref="tns:raport-fin" minOccurs="0" maxOccurs="unbounded" />
                                    <xs:element ref="tns:raport-dok" minOccurs="0" maxOccurs="unbounded" />
                                    <xs:element name="raport-z-rej-zap" type="tns:Raport-z-rej-zap" minOccurs="0" maxOccurs="unbounded" />
                                </xs:choice>
                            </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="suma-kontr" type="tns:TypSumaKontrolna" minOccurs="0" />
        </xs:sequence>
        <xs:element name="blad-przetw" type="tns:TypBladPrzetw" />
        <xs:element name="blad-struktury" type="tns:TypKomunikatAdministracyjny">
            <xs:annotation>
                <xs:documentation>zadanie operacji na bazie danych odrzucone z powodu bledow struktury (rezultat = blad struktury).</xs:documentation>
            </xs:annotation>
        </xs:element>
        <xs:element name="certyfikat" type="tns:TypRaportCertyfikat" />
    </xs:choice>
</xs:complexType>

Or delete from wsdl element:

<wsdl:operation name="pobranie-raportu-z-rej-zap">

AFAIK You can't call this operation - it is reserved for BIG Infomonitor use.

1
votes

WSDL it's correctly defined, that's why all analyzers are you giving correct answer. The main problem but it's that uses some objects referenced at https://www.bik.pl/cc/, that seems it's not serving that objects correctly, or cannot be accessed statically, and that's why appears that warnings at the webservice reference load.

As wsdl just got definitions of structure of methods & types used in an WS request, there's no real need to load it dinamically. So, yo can download the WSDL file, modify it if you're in need, and then charge it in VS. Anyway, I'm suspecting that you can use that webservice ignoring that warnings. Had you tried it?

1
votes

You can try to change this part, at the first of the wsdl file, replacing references to http://bik.pl/cc/big with some ones equivalents, or if you could access to that definitions in some other way, then save them to file & change wsdl to access to your saved files. For example, we see that you got dluznik.xsd. As well, if you see some namespaces are not beign used anymore in the wsdl, you can, directly, try to remove it.

Anyway, as told in my last comment, I think that problem it's just WSDL it's not Microsoft WCF compliant.

PD : Had you tried to use contract agreement when retrieving service reference? Difference using proxy classes will be just using generated objects for request/response, but it will be more contraint using that WS.

   <wsdl:definitions name="big" targetNamespace=**"http://bik.pl/cc/big"** 
xsi:schemaLocation=**"http://bik.pl/cc/big big.xsd"** xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:tns2="http://bik.pl/cc/big/internal" xmlns:tns=**"http://bik.pl/cc/big"** xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ws="http://www.example.com/webservice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
   <wsdl:types>
      <xsd:schema targetNamespace="http://bik.pl/cc/big/internal" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
         <xsd:import namespace="http://bik.pl/cc/big" schemaLocation="dluznik.xsd"/>
         <xs:element name="brak-odp-od-im" type="xs:string"/>
      </xsd:schema>
      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
         <xsd:import namespace=**"http://bik.pl/cc/big"** schemaLocation="dluznik.xsd"/>
      </xsd:schema>
   </wsdl:types>
0
votes

Your target resource was produced for .Net 4.5. You will either have to choose a new target location with the applicable .Net you wish to use for a service reference, or install a local copy of the wdsl.exe to your machine.

Reinstall .NET Framework 4.6 and install Microsoft .NET Framework 4.6.1 Developer Pack. Then use wsdl.exe which is located here:

C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools

Compile the proxy class into an assembly file and reference it in your project. Add missing assemblies if needed (i.e. System.Web.Services.dll).