简体   繁体   中英

Import wsdl file to xsd file

I want to generate class from soap xml via using xsd. I've been successful so far, but now, I've this soap message:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" 
    xmlns:tds="http://www.onvif.org/ver10/device/wsdl"> 
    <SOAP-ENV:Body> 
        <tds:GetSystemDateAndTime/> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope>

xsd will generate this:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Envelope" targetNamespace="http://www.w3.org/2003/05/soap-envelope"
xmlns:mstns="http://www.w3.org/2003/05/soap-envelope"
xmlns="http://www.w3.org/2003/05/soap-envelope"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified"
xmlns:app1="http://www.onvif.org/ver10/device/wsdl">
    <xs:import namespace="http://www.onvif.org/ver10/device/wsdl" schemaLocation="GetSystemDateAndTime_app1.xsd" />
    <xs:element name="Envelope" msdata:IsDataSet="true" msdata:Locale="en-US" msdata:Prefix="SOAP-ENV">
        <xs:complexType>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element name="Body" msdata:Prefix="SOAP-ENV">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element ref="app1:GetSystemDateAndTime" minOccurs="0" />
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:choice>
        </xs:complexType>
    </xs:element>
</xs:schema>

This xmlns:tds="http://www.onvif.org/ver10/device/wsdl" is link on this document .

As I said, so far, I just downloaded file, that was in schemaLocation attribute, put it to same folder like xsd file and changed path. Then I used "xsd myXsdFile.xsd otherXsdFiles.xsd /c". But with wsdl file, this isn't possible. SchemaLocation attribute doesn't take wsdl file and of course when I use xsd commnand, I will receive message that GetSystemDateAndTime doesn't exist. I understand that wsdl file is very different from xsd, but I can't take a right way, how to join this file with my xsd file. Any advice pls? Thx

To rephrase your question as I understood it, you're basically asking how to have your generated XSD file point to the real definition of the app1:GetSystemDateAndTime element, instead of GetSystemDateAndTime_app1.xsd ; the issue being the definition of app1:GetSystemDateAndTime is within an <xs:schema/> element within the <wsdl:types/> of a WSDL file located at http://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl .

If you're limiting your options only to your generated XSD and the WSDL you downloaded, the short answer is no, you cannot have an XSD reference content from another XSD defined inside a WSDL file.

It is not clear why you wouldn't use the built-in VS tooling (Service Reference or Web Reference if you're on older version), or svcutil.exe to generate your client code. It is very unusual to bind code from an XSD reversed from a SOAP Envelope XML. It is possible nonetheless, SOAP if XML afterall; I just never saw it before...

If you still want to "join", and willing to make some manual changes, then you could do it two ways.

The long way is to download all the files (the WSDL + the XSD). From a command prompt you could use svcutil like this:

svcutil /t:metadata /directory:d:\temp\11 http://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl

It'll output like this:

Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.1]
Copyright (c) Microsoft Corporation.  All rights reserved.

Attempting to download metadata from 'http://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl' using WS-Metadata Exchange or DISCO.
Saving downloaded metadata files...
d:\temp\11\www.onvif.org.ver10.schema.xsd
d:\temp\11\www.w3.org.2004.08.xop.include.xsd
d:\temp\11\www.w3.org.XML.1998.namespace.xsd
d:\temp\11\www.onvif.org.ver10.device.wsdl
d:\temp\11\www.w3.org.2005.08.addressing.xsd
d:\temp\11\docs.oasis-open.org.wsrf.bf-2.xsd
d:\temp\11\www.w3.org.2005.05.xmlmime.xsd
d:\temp\11\docs.oasis-open.org.wsn.t-1.xsd
d:\temp\11\docs.oasis-open.org.wsn.b-2.xsd

From the WSDL file, manually rip the XSD content out in a file devicemgmtwsdl.xsd, in the same folder; edit and match the imports in all the files to match the XSD file names as downloaded. Reference the devicemgmt.wsdl instead of GetSystemDateAndTime_app1.xsd and you're good to go.

Alternatively, with an XSD refactoring tool, you could use a simple Import XML Schema files wizard: point it at the WSDL file, specify a folder and click OK. The files will be there for you to reference them as you like.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM