在 ASP.NET Core-6 Web API 中,我生成了如下所示的 WSDL SOAP 服务:
dotnet tool install -g dotnet-svcutil
dotnet-svcutil http://thirdpartyapi:3209/SchoolService/SchoolService?WSDL
然后我得到这个:
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);
}
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);
}
}
实施:
公共类 StudentDetailService : IStudentDetailService { 私人只读 SchoolServiceSEIClient _client; 公共 StudentDetailService( SchoolServiceSEIClient客户端 ) { _client = 客户; } .... }
想注射的时候,我是这样操作的:
DI:
public static class DIServiceExtension
{
public static void AddDependencyInjection(this IServiceCollection services)
{
services.AddTransient<SchoolServiceSEIClient, SchoolServiceSEIClient>();
}
}
Program.cs
builder.Services.AddDependencyInjection();
但是我得到了这个错误:
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)
我想注入 SchoolServiceSEI 和 SchoolServiceSEIClient
如何实现 DependencyInjection 以注入 SchoolServiceSEI 和 SchoolServiceSEIClient?