【问题标题】:wsdl based webservice in .net changes <xs> tag to <s>.net 中基于 wsdl 的 Web 服务将 <xs> 标记更改为 <s>
【发布时间】:2018-10-02 10:42:27
【问题描述】:

我有客户端发送的带有此规则的 wsdl 文件:

<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://example.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="PersonInfoTransactionService" targetNamespace="http://example.com/">
  <wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://example.com/" elementFormDefault="unqualified" targetNamespace="http://example.com/" version="1.0">

  <xs:element name="getPersonInfo" type="tns:getPersonInfo"/>

  <xs:element name="getPersonInfoResponse" type="tns:getPersonInfoResponse"/>

  <xs:element name="personInfoRequest" type="tns:PersonInfoRequest"/>

  <xs:element name="personInfoResponse" type="tns:PersonInfoResponse"/>

  <xs:complexType name="getPersonInfo">
    <xs:sequence>
      <xs:element minOccurs="1" maxOccurs="1" name="PersonInfoRequest" type="tns:PersonInfoRequest"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="PersonInfoRequest">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="1" name="adress" type="xs:string"/>
      <xs:element minOccurs="0" maxOccurs="1" name="dob" type="xs:string"/>
      <xs:element minOccurs="0" maxOccurs="1" name="sex" type="tns:sex"/>
      <xs:element minOccurs="0" maxOccurs="1" name="nationality" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="getPersonInfoResponse">
    <xs:sequence>
      <xs:element minOccurs="0" name="PersonInfoResponse" type="tns:PersonInfoResponse"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="PersonInfoResponse">
    <xs:sequence>

      <xs:element minOccurs="0" maxOccurs="1" name="last_name" type="xs:string"/>
      <xs:element minOccurs="0" maxOccurs="1" name="first_name" type="xs:string"/>
      <xs:element minOccurs="0" maxOccurs="1" name="fathers_name" type="xs:string"/>
      <xs:element minOccurs="0" maxOccurs="1" name="adress" type="xs:string"/>
      <xs:element minOccurs="0" maxOccurs="1" name="dob" type="xs:string"/>
      <xs:element minOccurs="0" maxOccurs="1" name="sex" type="tns:sex"/>
      <xs:element minOccurs="0" maxOccurs="1" name="nationality" type="tns:nationality"/>
    </xs:sequence>
  </xs:complexType>

   <xs:simpleType name="sex">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Male"/>
      <xs:enumeration value="Female"/>
      <xs:enumeration value="Unknown"/>
    </xs:restriction>
  </xs:simpleType>

    <xs:simpleType name="nationality">
        <xs:restriction base="xs:string">
            <xs:enumeration value="AFGHANISTAN"/>
            <xs:enumeration value="ALAND ISLANDS"/>
            <xs:enumeration value="ALBANIA"/>
        </xs:restriction>
    </xs:simpleType>

</xs:schema>
  </wsdl:types>
  <wsdl:message name="getPersonInfoResponse">
    <wsdl:part element="tns:getPersonInfoResponse" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="getPersonInfo">
    <wsdl:part element="tns:getPersonInfo" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="PersonInfoTransaction">
    <wsdl:operation name="getPersonInfo">
      <wsdl:input message="tns:getPersonInfo" name="getPersonInfo">
    </wsdl:input>
      <wsdl:output message="tns:getPersonInfoResponse" name="getPersonInfoResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="PersonInfoTransactionServiceSoapBinding" type="tns:PersonInfoTransaction">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="getPersonInfo">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="getPersonInfo">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="getPersonInfoResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="PersonInfoTransactionService">
    <wsdl:port binding="tns:PersonInfoTransactionServiceSoapBinding" name="PersonInfoTransactionPort">
      <soap:address location="http://localhost/demo/PersonInfoTransaction"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

所以,我创建了相应的 .cs 文件,以便它可以为我生成上述请求的 wsdl。但它生成了下面的wsdl:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http:/example.coom/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http:/example.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http:/example.com/">
      <s:element name="getPersonInfo">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="personInfoRequest" type="tns:PersonInfoRequest" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:complexType name="PersonInfoRequest">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="1" name="adress" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="dob" type="s:string" />
          <s:element minOccurs="1" maxOccurs="1" name="sex" nillable="true" type="tns:sex" />
          <s:element minOccurs="0" maxOccurs="1" name="nationality" type="s:string" />
        </s:sequence>
      </s:complexType>
      <s:simpleType name="sex">
        <s:restriction base="s:string">
          <s:enumeration value="Male" />
          <s:enumeration value="Female" />
          <s:enumeration value="Unknown" />
        </s:restriction>
      </s:simpleType>
      <s:element name="getPersonInfoResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="getPersonInfoResult" type="tns:ArrayOfPersonInfoResponse" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:complexType name="ArrayOfPersonInfoResponse">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="unbounded" name="PersonInfoResponse" nillable="true" type="tns:PersonInfoResponse" />
        </s:sequence>
      </s:complexType>
      <s:complexType name="PersonInfoResponse">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="1" name="fathers_name" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="adress" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="dob" type="s:string" />
          <s:element minOccurs="1" maxOccurs="1" name="sex" nillable="true" type="tns:sex" />
          <s:element minOccurs="1" maxOccurs="1" name="nationality" nillable="true" type="tns:nationality" />
        </s:sequence>
      </s:complexType>
      <s:simpleType name="nationality">
        <s:restriction base="s:string">
          <s:enumeration value="AFGHANISTAN" />
          <s:enumeration value="ALAND ISLANDS" />
          <s:enumeration value="ALBANIA" />
          <s:enumeration value="ALGERIA" />

        </s:restriction>
      </s:simpleType>
    </s:schema>
  </wsdl:types>
  <wsdl:message name="getPersonInfoSoapIn">
    <wsdl:part name="parameters" element="tns:getPersonInfo" />
  </wsdl:message>
  <wsdl:message name="getPersonInfoSoapOut">
    <wsdl:part name="parameters" element="tns:getPersonInfoResponse" />
  </wsdl:message>
  <wsdl:portType name="PersonInfoTransactionServiceSoap">
    <wsdl:operation name="getPersonInfo">
      <wsdl:input message="tns:getPersonInfoSoapIn" />
      <wsdl:output message="tns:getPersonInfoSoapOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="PersonInfoTransactionServiceSoap" type="tns:PersonInfoTransactionServiceSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="getPersonInfo">
      <soap:operation soapAction="http:/example.com/getPersonInfo" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="PersonInfoTransactionServiceSoap12" type="tns:PersonInfoTransactionServiceSoap">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="getPersonInfo">
      <soap12:operation soapAction="http:/example.com/getPersonInfo" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="PersonInfoTransactionService">
    <wsdl:port name="PersonInfoTransactionServiceSoap" binding="tns:PersonInfoTransactionServiceSoap">
      <soap:address location="http://localhost:7345/abc/PersonInfoTransactionService.asmx" />
    </wsdl:port>
    <wsdl:port name="PersonInfoTransactionServiceSoap12" binding="tns:PersonInfoTransactionServiceSoap12">
      <soap12:address location="http://localhost:7345/abc/PersonInfoTransactionService.asmx" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

我的主要问题是我是否可以直接使用 WSDL 而不必使用 .cs 文件来创建 WSDL 文件,或者我可以修改什么来创建标签而不是文档中的标签。或者如何使用web-services方法控制或修改WSDL?

【问题讨论】:

    标签: asp.net web-services soap wsdl soap-client


    【解决方案1】:

    被引用的 xs 和 s 是命名空间前缀。实际的命名空间前缀并不重要,重要的是它对应的是什么。

    xs 指的是命名空间“http://www.w3.org/2001/XMLSchema”(xmlns:xs="http://www.w3.org/2001/XMLSchema") s 也指相同的命名空间(xmlns:s="http://www.w3.org/2001/XMLSchema")

    所以 s 或 xs 无关紧要。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-05
      • 1970-01-01
      • 2013-07-21
      • 1970-01-01
      • 2011-02-03
      • 2015-12-23
      相关资源
      最近更新 更多