当验证规则的一部分在WSDL中时,如何使用XSD验证XML

时间:2017-05-04 06:54:32

标签: c# .net xml xsd wsdl

我使用C#,.NET 4.5,控制台应用程序。 我在服务引用中添加了WSDL文件。内部WSDL是验证规则,如:

<div class="loadPagejQuery">
    <script>
        if (window.jQuery) {  
            // jQuery is loaded  
            console.log("jQuery is loaded  ");
            } else {
            // jQuery is not loaded
            console.log("jQuery is not loaded  ");
            (function () {
                // Load the script
                var script = document.createElement("SCRIPT");
                script.src = '/Style/js/jquery-1.10.2.js';
                script.type = 'text/javascript';
                document.getElementsByClassName("loadPagejQuery")[0].appendChild(script);
            })();
        }
    </script>
</div>

<script id="the_jquery_ui" src="/Style/jquery-ui-1.12.1/jquery-ui.js"></script>//Uncaught ReferenceError: $ is not defined
<link rel="stylesheet" type="text/css" href="/Style/jquery-ui-1.12.1/jquery-ui.css"/>

<script>
    $(document).ready(function () {
        //Uncaught ReferenceError: $ is not defined
    });
</script>

还有XSD文件,其中包含验证规则的详细信息:

<xs:complexType name="xRequest">
  <xs:sequence>
    <xs:element name="SenderDateTime" type="ip:grDateTime"/>
    <xs:element name="SenderId" type="ip:grIdentifier"/>
  </xs:sequence>
</xs:complexType>

我已经在Reference.cs中自动生成了WSDL中的属性,如:

<xs:simpleType name="grDateTime">
    <xs:restriction base="xs:dateTime">
        <xs:pattern value="[0-9]{4,4}\-[0-9]{2,2}\-[0-9]{2,2}[T][0-9]{2,2}:[0-9]{2,2}:[0-9]{2,2}(\.[0-9]{1,6}){0,1}"/>
    </xs:restriction>
</xs:simpleType>

我将xRequest对象序列化为XML,我想验证它。 当部分验证规则是在WSDL中时,如何使用XSD验证XML?

1 个答案:

答案 0 :(得分:3)

它不是那么直接......看看这个article(步骤4,5和11),我认为它基本上是你想要做的(客户端),但它也显示如何进行验证服务器端。