Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有参数的C#SOAP操作契约在WSDL中不存在_C#_Soap_.net 5_Webapi_Operationcontract - Fatal编程技术网

带有参数的C#SOAP操作契约在WSDL中不存在

带有参数的C#SOAP操作契约在WSDL中不存在,c#,soap,.net-5,webapi,operationcontract,C#,Soap,.net 5,Webapi,Operationcontract,我已经使用.netCore 5 WebApi编写了一个SOAP服务器。在本文中,我实现了一个名为TestMethodAsync(TestRequest-request)的TestMethod,但在我的WSDL文件中,参数并没有为这个方法命名 我的代码: [ServiceContract] public interface ITestService { [OperationContract] public Task<TestResponse> TestMethodAsy

我已经使用.netCore 5 WebApi编写了一个SOAP服务器。在本文中,我实现了一个名为
TestMethodAsync(TestRequest-request)
的TestMethod,但在我的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; }
}
[服务合同]
公共接口ITestService
{
[经营合同]
公共任务TestMethodAsync(TestRequest请求);
}
公共类TestService:ITestService
{
公共任务TestMethodAsync(TestRequest请求)
{
返回新任务(()=>
{
返回新的TestResponse
{
TestBaseProperty=request.TestBaseProperty,
TestProperty=request.TestProperty,
};
});
}
}
[数据合同]
公共类TestPropertyClass
{
[数据成员]
公共字符串文本{get;set;}
}
[数据合同]
公共类TestResponseBase
{
[数据成员]
公共TestPropertyClass TestBaseProperty{get;set;}
}
[数据合同]
公共类TestResponse:TestResponseBase
{
[数据成员]
公共TestPropertyClass TestProperty{get;set;}
}
[数据合同]
公共类TestRequestBase
{
[数据成员]
公共TestPropertyClass TestBaseProperty{get;set;}
}
[数据合同]
公共类TestRequest:TestRequestBase
{
[数据成员]
公共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没有输入参数。

如果更改
TestMethodAsync
(比如对TestMethodNotSync)的名称,会发生什么情况?我想知道您是否遇到了一个问题,即WCF基础设施假定它是唯一将事物命名为XxxAsync的事物。WSDL使用的都是
TestMethod
,而不是
TestMethodAsync
@Flydog57,然后生成器将该方法重新命名为
TestMethodNotSync
,但您可能不想看到任何其他更改。WCF的异步性比任务并行库(以及
Task
)早了很多。我不知道它们是如何混合的。this()更现代,并且包含了对基于
任务的异步的描述