我想从wsdl和一些xsd文件生成代理类(C#) . wsdl和xsd文件都位于我磁盘上的同一文件夹中 . 我发出的命令是:

svcutil.exe AuthenticateAndGetAssertionsSOAP12v2.wsdl .xsd / t:code / l:cs /o:AuthAndGetAssertionsProxy.cs / n :,TestNamespace

但是没有生成代理类,我收到此错误:

如果包含-annotation-以外的任何子节点,'SchemaLocation'必须成功解析 .

svcutil还声明有问题的文档ID是http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd .

其中一个xsd文件确实有效地重新定义了此命名空间中定义的complexType,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    <xs:redefine schemaLocation="oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <xs:complexType name="UsernameTokenType">
            <xs:complexContent>
                <xs:extension base="UsernameTokenType">
                    <xs:sequence>
                        <xs:element name="NewPassword" type="xs:base64Binary"/>
                    </xs:sequence>
                </xs:extension>
            </xs:complexContent>
        </xs:complexType>
    </xs:redefine>
</xs:schema>

我尝试完全限定schemaLocation URI,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
       <xs:redefine schemaLocation="file:///C:/AuthAndGetAssertionsSOAP12v2/oasis-200401-wss-wssecurity-secext-1.0.xsd">    
       <xs:complexType name="UsernameTokenType">
            <xs:complexContent>
                <xs:extension base="UsernameTokenType">
                    <xs:sequence>
                        <xs:element name="NewPassword" type="xs:base64Binary"/>
                    </xs:sequence>
                </xs:extension>
            </xs:complexContent>
        </xs:complexType>
    </xs:redefine>
</xs:schema>

其中C:\ AuthAndGetAssertionsSOAP12v2是wsdl和xsd文件的实际路径,但我仍然无法使其正常工作 .

作为参考,这是在oasis-200401-wss-wssecurity-secext-1.0.xsd中定义complexType UsernameTokenType的方式:

<xsd:complexType name="UsernameTokenType">
        <xsd:annotation>
            <xsd:documentation>This type represents a username token per Section 4.1</xsd:documentation>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element name="Username" type="wsse:AttributedString"/>
            <xsd:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
        <xsd:attribute ref="wsu:Id"/>
        <xsd:anyAttribute namespace="##other" processContents="lax"/>
    </xsd:complexType>

我搜索了很多,但我找不到任何解决方案,但看完这篇文章后

svcUtil error 'SchemaLocation' must successfully resolve if <redefine> contains any child other than <annotation>

我开始认为问题可能出在wsdl的其他地方 . 有什么建议?