0

我已经使用 .netCore 5 WebApi 编写了一个 SOAP 服务器。在这我已经实现了一个名为 TestMethodTestMethodAsync(TestRequest request)但在我的 WSDL 文件中的参数不是为此方法命名的

我的代码:

[ServiceContract]
public interface ITestService
{
    [OperationContract]
    public Task<TestResponse> TestMethodAsync(TestRequest request);
}

public class TestService: ITestService
{
    public Task<TestResponse> TestMethodAsync(TestRequest request)
    {
        return new Task<TestResponse>(() =>
        {
            return new TestResponse
            {
                TestBaseProperty = request.TestBaseProperty,
                TestProperty = request.TestProperty,
            };
        });
    }
}

[DataContract]
public class TestPropertyClass 
{
    [DataMember]
    public string Text { get; set; }
}

[DataContract]
public class TestResponseBase 
{
    [DataMember]
    public TestPropertyClass TestBaseProperty { get; set; }
}

[DataContract]
public class TestResponse : TestResponseBase
{
    [DataMember]
    public TestPropertyClass TestProperty { get; set; }
}

[DataContract]
public class TestRequestBase
{
    [DataMember]
    public TestPropertyClass TestBaseProperty { get; set; }
}

[DataContract]
public class TestRequest : TestRequestBase
{
    [DataMember]
    public TestPropertyClass TestProperty { get; set; }
}

和 WSDL 文件:

    <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:http="http://schemas.microsoft.com/ws/06/2004/policy/http" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" targetNamespace="http://tempuri.org/" name="ITestService" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <xsd:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
      <xsd:import namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
      <xsd:import namespace="http://schemas.datacontract.org/2004/07/System" />
      <xsd:element name="TestMethod">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element minOccurs="0" maxOccurs="1" name="request" type="tns:TestRequest" />
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
      <xsd:element name="TestMethodResponse">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element minOccurs="0" maxOccurs="1" name="TestMethodResult" type="tns:TestResponse" />
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
      <xsd:complexType name="TestRequest">
        <xsd:sequence>
          <xsd:element minOccurs="0" maxOccurs="1" name="TestProperty" type="tns:TestPropertyClass" />
          <xsd:element minOccurs="0" maxOccurs="1" name="TestBaseProperty" type="tns:TestPropertyClass" />
        </xsd:sequence>
      </xsd:complexType>
      <xsd:complexType name="TestResponse">
        <xsd:sequence>
          <xsd:element minOccurs="0" maxOccurs="1" name="TestProperty" type="tns:TestPropertyClass" />
          <xsd:element minOccurs="0" maxOccurs="1" name="TestBaseProperty" type="tns:TestPropertyClass" />
        </xsd:sequence>
      </xsd:complexType>
      <xsd:complexType name="TestPropertyClass">
        <xsd:sequence>
          <xsd:element minOccurs="0" maxOccurs="1" name="Text" type="xsd:string" />
        </xsd:sequence>
      </xsd:complexType>
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="ITestService_TestMethod_InputMessage" />
  <wsdl:message name="ITestService_TestMethod_OutputMessage">
    <wsdl:part name="parameters" element="tns:TestMethodResponse" />
  </wsdl:message>
  <wsdl:portType name="ITestService">
    <wsdl:operation name="TestMethod">
      <wsdl:input message="tns:ITestService_TestMethod_InputMessage" />
      <wsdl:output message="tns:ITestService_TestMethod_OutputMessage" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="BasicHttpBinding" type="tns:TestService" style="document">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="TestMethod">
      <soap:operation soapAction="http://tempuri.org/TestService/TestMethod" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="ITestService">
    <wsdl:port name="BasicHttpBinding" binding="tns:BasicHttpBinding">
      <soap:address location="https://localhost:44351/TestService.asmx" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

但问题是,当我生成客户端时,TestMethodAsync 没有输入参数。

4

0 回答 0