XML模式没有限制

时间:2015-03-20 10:35:17

标签: php xml soap xsd wsdl

这是biodata.xsd文件

<?xml version="1.0" encoding="utf-8"?>

<xs:schema  elementFormDefault="qualified" 
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            targetNamespace="TestNamespace">

            <xs:element name="Biodata">
              <xs:complexType>
                <xs:sequence>

                  <xs:element name="insertNameRequest">
                    <xs:simpleType>
                      <xs:restriction base="xs:string">
                        <xs:maxLength value="30"/>
                      </xs:restriction>
                    </xs:simpleType>
                  </xs:element>

                  <xs:element name="BiodataPortType"/>
                  <xs:element name="BiodataBinding"/>
                  <xs:element name="BiodataService"/>

                </xs:sequence>
              </xs:complexType>
            </xs:element>

</xs:schema>

这是biodata.wsdl

<?xml version ='1.0' encoding ='UTF-8' ?>

<definitions name="Biodata"
             targetNamespace="urn:TestNamespace"
             xmlns="http://schemas.xmlsoap.org/wsdl/"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:tns="TestNamespace"
             xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
             xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'>

             <import namespace="TestNamespace" location="biodata.xsd"/>

             <message name='insertNameRequest'>
                 <part name='name' element="Biodata"/>
             </message>

             <portType name='BiodataPortType'>
                 <operation name='insertName'>
                   <input message='tns:insertNameRequest'/>
                 </operation>
             </portType>

             <binding name='BiodataBinding' type='tns:BiodataPortType'>
                 <soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/>
                   <operation name='insertName'>
                     <soap:operation soapAction='insertName'/>
                       <input>
                         <soap:body use='encoded' namespace='urn:examples:biodata'
                           encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
                       </input>
                   </operation>
             </binding>

             <service name='BiodataService'>
                 <port name='BiodataPort' binding='tns:BiodataBinding'>
                      <soap:address 
                      location='http://localhost/Kevin/FirstWebService/OneWay/server.php'/>
                 </port>
             </service> 

</definitions>

server.php

<?php
require 'biodata_functions.php';
//require 'SoapFault.php';

ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer("http://localhost/Kevin/FirstWebService/OneWay/biodata.wsdl");
/*$server->addFunction("getName");
*/

$server->addFunction("insertName");
/*$server->addFunction("insertAge");
*/

$server->handle();
?>

客户test.php的

<?php
    $client = new SoapClient("http://localhost/Kevin/FirstWebService/OneWay/biodata.wsdl");
    $return = $client->insertName($name);

    header("Location: http://localhost/Kevin/FirstWebService/OneWay/client.html");
    die();
?>

client.html

<!DOCTYPE html>
<html>
<head>
  <title>OneWay</title>
</head>

<form action="client_test.php" method=POST>
NAME:<br>
<input type="text" name="name">
<br>

<input type="Submit" value="Submit">
</form>

</html>

问题:我不能限制使用xsd文件,即使我已经声明最大长度为30,它仍然输入超过30的值......我的代码有问题吗?任何帮助将不胜感激,谢谢:D

0 个答案:

没有答案