如何从XSD和WSDL文件创建Web服务?

时间:2019-06-11 17:11:38

标签: asp.net-mvc web-services soap xsd wsdl

这是问题所在: 我有一个.WSDL文件和.XSD文件,我需要创建一个Web服务以将其合并到解决方案中。 我所做的第一件事是创建一个新项目=> WCF => WCF Service Application 之后,我知道我需要一些类来创建围绕它的Web服务,因此我尝试了不同的方法来从WSDL和XSD文件生成它们,但这没有用。

我尝试过服务器方式:

1:xsd /c myFile.xsd /n:mynamespace

但是给了我几个错误:

Schema validation warning: The type attribute cannot be present with either simpleType or complexType.

 <xsd:complexType name="R000000">
                <xsd:annotation>
                    <xsd:documentation xml:lang="EN">Cabeçalho</xsd:documentation>
                </xsd:annotation>
                <xsd:sequence>
                    <xsd:element name="R00000100" type="datehourminsec">
                        <xsd:annotation>
                            <xsd:documentation>Data / Hora</xsd:documentation>
                        </xsd:annotation>
                        <xsd:simpleType>
                            <xsd:restriction base="xsd:string">
                                <xsd:length value="14"/>
                            </xsd:restriction>
                        </xsd:simpleType>
                    </xsd:element>
                    <xsd:element name="R00000110" type="version">
                        <xsd:annotation>
                            <xsd:documentation>Versão</xsd:documentation>
                        </xsd:annotation>
                </xsd:sequence>
            </xsd:complexType>

2:svcutil.exe /language:C# /out:myService.cs /n:*,mynamespace myFile.wsdl

如果我尝试使用此方法也给了我很多错误,

Error: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: The type attribute cannot be present with either simpleType or complexType.
XPath to Error Source: //wsdl:definitions[@targetNamespace='myurl.pt/myservice/service']/wsdl:portType[@name='ELServiceSoap']


Error: 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='myurl.pt/myservice/service']/wsdl:portType[@name='ELServiceSoap']
XPath to Error Source: //wsdl:definitions[@targetNamespace='myurl.pt/myservice/service']/wsdl:binding[@name='ELServiceSoap']


Error: 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='myurl.pt/myservice/service']/wsdl:binding[@name='ELServiceSoap']
XPath to Error Source: //wsdl:definitions[@targetNamespace='myurl.pt/myservice/service']/wsdl:service[@name='ELService']/wsdl:port[@name='ELServiceSoap']


Generating files...
Warning: No code was generated.
If you were trying to generate a client, this could be because the metadata documents did not contain any valid contracts or services
or because all contracts/services were discovered to exist in /reference assemblies. Verify that you passed all the metadata documents to the tool.

Warning: If you would like to generate data contracts from schemas make sure to use the /dataContractOnly option.

即使我将命令与/ dataContractOnly选项一起使用,它也会恢复为xsd命令中出现的错误:

Error: An error occurred in the tool.

Error: The type attribute cannot be present with either simpleType or complexType.

我不确定是否朝着正确的方向创建Web服务,但是如果我是正确的,我该如何解决这个错误?

0 个答案:

没有答案