ASP.NET Core - 如何解决不支持配置文件。在 SWDL SOAP 服务中的 System.ServiceModel.ClientBase`1..ctor()

问题描述 投票:0回答:0

我得到了第三方 WSDL SOAP 服务,可以在 ASP.NET Core 6 Web API 中使用,然后生成 JSON 响应服务。这是给定的 WSDL SOAP 服务:

http://thirdpartyapi:3209/SchoolService/SchoolService?WSDL

我在不同的时间用这两种方法消费,还是一样的错误:

方法一: Service Reference using Connected Service

方法二:

dotnet tool install -g dotnet-svcutil
dotnet-svcutil http://thirdpartyapi:3209/SchoolService/SchoolService?WSDL

我叫它

SchoolServiceReference

所以这里是生成的Service Reference的一部分

DTO

public class StudentDetailDto
{
    public string StudentRef { get; set; }
    public string StudentCode { get; set; }
}

然后我创建了服务接口和实现

EmployeeService - 接口:

任务 GetStudentDetailAsync(StudentDetailDto 模型);

实施:

public class StudentDetailService : IStudentDetailService
{
    private readonly SchoolServiceSEIClient _client;
    public StudentDetailService(
        SchoolServiceSEIClient client
        )
    {
        _client = client;
    }
    public async Task<QueryStudentResponse> GetStudentDetailAsync(StudentDetailDto model)
    {
        var request = new QUERYSTUDENT_REQ();
        request.SCH_HEADER = new SCH_HEADERType();
        request.SCH_HEADER.USERNAME = "username1";
        request.SCH_HEADER.PASSWORD = "password1";

        request.SCH_BODY = new QUERYSTUDENT_BODY
        {
            StudentQ = new StudentQueryType
            {
                REF = model.StudentRef,
                COD = model.StudentCode
            }
        };

        var response = await _client.QueryStudentAsync(request);
        return response;
    }
}

注意: QueryStudentResponse 来自生成的服务参考

DI:

    public static class DIServiceExtension
    {
        public static void AddDependencyInjection(this IServiceCollection services)
        {
            services.AddScoped<IStudentDetailService, StudentDetailService>();
            services.AddTransient<SchoolServiceSEIClient, SchoolServiceSEIClient>();  
        }
    }

程序.cs:

builder.Services.AddDependencyInjection();

然后,然后控制器:

控制器:

[Route("api/[controller]")]
[ApiController]
public class StudentController : ControllerBase
{
    private readonly IStudentDetailService _studentDetailService;

    public StudentController(
        IStudentDetailService studentDetailService
        )
    {
        _studentDetailService = studentDetailService;
    }

    [HttpGet("StudentDetail")]
    public async Task<IActionResult> GetStudentDetailAsync([FromQuery] StudentDetailDto model)
    {
        var result = await _studentDetailService.GetStudentDetailAsync(model);
        return Ok(result);
    }
}

当我在 Swagger 或 POSTMAN 上提交请求时(使用 HtttPost 或 HttpGet 请求),我得到了这个错误:

System.PlatformNotSupportedException: Configuration files are not supported. at System.ServiceModel.ClientBase`1..ctor() at SchoolServiceSEIClient..ctor() in C:\SchoolApp.Common\SchoolService.cs:line 149
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)

亮点:

var response = await _client.QueryStudentAsync(request)

这也是第 149 行,错误在生成的服务参考中引用

  public SchoolServiceSEIClient()  { }

您可以在下面找到生成的服务参考:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://SchoolService.types.ws.gw.thirdpartyapi.com", ConfigurationName="SchoolServiceSEI")]

public interface SchoolServiceSEI
{

    [System.ServiceModel.OperationContractAttribute(Action="http://SchoolService.types.ws.gw.thirdpartyapi.com/SchoolServiceSEI/QueryStudent" +
        "IORequest", ReplyAction="http://SchoolService.types.ws.gw.thirdpartyapi.com/SchoolServiceSEI/QueryStudent" +
        "IOResponse")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    QueryStudentResponse QueryStudent(QueryStudentRequest request);
    
    [System.ServiceModel.OperationContractAttribute(Action="http://SchoolService.types.ws.gw.thirdpartyapi.com/SchoolServiceSEI/QueryStudent" +
        "IORequest", ReplyAction="http://SchoolService.types.ws.gw.thirdpartyapi.com/SchoolServiceSEI/QueryStudent" +
        "IOResponse")]
    System.Threading.Tasks.Task<QueryStudentResponse> QueryStudentAsync(QueryStudentRequest request);
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class QueryStudentResponse
{
    
    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://thirdpartyapi.com/service/SchoolService", Order=0)]
    public QUERYSTUDENT_REQ QUERYSTUDENT_REQ;
    
    public QueryStudentResponse()
    {
    }
    
    public QueryStudentResponse(QUERYSTUDENT_REQ QUERYSTUDENT_REQ)
    {
        this.QUERYSTUDENT_REQ = QUERYSTUDENT_REQ;
    }
}
   
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.8.3928.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://thirdpartyapi.com/service/SchoolService")]
public partial class QUERYSTUDENT_REQ
{
    
    private SCH_HEADERType sCH_HEADERField;
    
    private QUERYSTUDENT_BODY sCH_BODYField;
    
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public SCH_HEADERType SCH_HEADER
    {
        get
        {
            return this.sCHHEADERField;
        }
        set
        {
            this.sCH_HEADERField = value;
        }
    }     

    [System.Xml.Serialization.XmlElementAttribute(Order=1)]
    public QUERYSTUDENT_BODY SCH_BODY
    {
        get
        {
            return this.sCH_BODYField;
        }
        set
        {
            this.sCH_BODYField = value;
        }
    }
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.8.3928.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://thirdpartyapi.com/service/SchoolService")]
public partial class SCH_HEADERType
{
    private string uSERNAMEField;
    private string pASSWORDField;
    private SCH_HEADERTypePARAM[] aDDLField;

    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public string USERNAME
    {
        get
        {
            return this.uSERNAMEField;
        }
        set
        {
            this.uSERNAMEField = value;
        }
    }
    
    [System.Xml.Serialization.XmlElementAttribute(Order=1)]
    public string PASSWORD
    {
        get
        {
            return this.pASSWORDField;
        }
        set
        {
            this.pASSWORDField = value;
        }
    }
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.8.3928.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://thirdpartyapi.com/service/SchoolService")]
public partial class QUERYSTUDENT_BODY
{
    
    private StudentQueryType studentField;
    
    [System.Xml.Serialization.XmlElementAttribute("StudentQ", Order=0)]
    public StudentQueryType StudentQ
    {
        get
        {
            return this.studentField;
        }
        set
        {
            this.studentField = value;
        }
    }
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.8.3928.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(TypeName="CustAcc-Query-IO-Type", Namespace="http://thirdpartyapi.com/service/FCUBSAccService")]
public partial class StudentQueryType
{
    
    private string eMPField;
    
    private string dEPField;
    
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public string REF
    {
        get
        {
            return this.rEFField;
        }
        set
        {
            this.rEFField = value;
        }
    }
    
    [System.Xml.Serialization.XmlElementAttribute(Order=1)]
    public string COD
    {
        get
        {
            return this.cODField;
        }
        set
        {
            this.cODField = value;
        }
    }
}

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
System.Threading.Tasks.Task<QueryStudentResponse> SchoolServiceSEIClient.QueryEmployeeAsync(QueryStudentRequest request)
{
    return base.Channel.QueryStudentAsync(request);
}

public System.Threading.Tasks.Task<QueryStudentResponse> QueryStudentAsync(QUERYSTUDENT_REQ)
{
    QueryStudentRequest inValue = new QueryStudentRequest();
    inValue.QUERYSTUDENT_REQ = QUERYSTUDENT_REQ;
    return ((SchoolServiceSEIClient)(this)).QueryStudentAsync(inValue);
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class QueryStudentResponse
{
    
    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://thirdpartyapi.com/service/SchoolService", Order=0)]
    public QUERYSTUDENT_RES QUERYSTUDENT_RES;
    
    public QueryStudentResponse()
    {
    }
    
    public QueryStudentResponse(QUERYSTUDENT_RES QUERYSTUDENT_RES)
    {
        this.QUERYSTUDENT_RES = QUERYSTUDENT_RES;
    }
}

public partial class SchoolServiceSEIClient : System.ServiceModel.ClientBase<SchoolServiceSEI>, SchoolServiceSEI
{
    
    public SchoolServiceSEIClient()
    {
    }
    
    public SchoolServiceSEIClient(string endpointConfigurationName) : 
            base(endpointConfigurationName)
    {
    }
    
    public SchoolServiceSEIClient(string endpointConfigurationName, string remoteAddress) : 
            base(endpointConfigurationName, remoteAddress)
    {
    }
    
    public SchoolServiceSEIClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(endpointConfigurationName, remoteAddress)
    {
    }
    
    public SchoolServiceSEIClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(binding, remoteAddress)
    {
    }

   [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    QueryStudentResponse SchoolServiceSEI.QueryStudent(QueryStudentRequest request)
    {
        return base.Channel.QueryCustAccIO(request);
    }
    
    public QUERYSTUDENT_RES QueryStudent(QUERYSTUDENT_REQ QUERYSTUDENT_REQ)
    {
        QueryStudentRequest inValue = new QueryStudentRequest();
        inValue.QUERYSTUDENT_REQ = QUERYSTUDENT_REQ;
        QueryStudentResponse retVal = ((SchoolServiceSEI)(this)).QueryStudent(inValue);
        return retVal.QUERYSTUDENT_RES;
    }
    
    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    System.Threading.Tasks.Task<QueryStudentResponse> SchoolServiceSEI.QueryStudentAsync(QueryStudentRequest request)
    {
        return base.Channel.QueryStudentAsync(request);
    }
    
    public System.Threading.Tasks.Task<QueryStudentResponse> QueryStudentAsync(QUERYSTUDENT_REQ QUERYSTUDENT_REQ)
    {
        QueryStudentRequest inValue = new QueryStudentRequest();
        inValue.QUERYSTUDENT_REQ = QUERYSTUDENT_REQ;
        return ((SchoolServiceSEI)(this)).QueryStudentAsync(inValue);
    }
}

我该如何解决这个问题?

c# asp.net-core asp.net-web-api soap wsdl
© www.soinside.com 2019 - 2024. All rights reserved.