ASP.NET Coreからアクセスする必要があるWCFサービスがあります。 WCF Connected Previewがインストールされ、プロキシが正常に作成されました。ASP.NetコアにWCFサービスクライアントを挿入する方法は?
それはサービスを呼び出すコンシューマークラスは、私はスタートアップクラスのConfigureServicesメソッドでIDocumentIntegrationを登録するにはどうすればよい
public class Consumer
{
private IDocumentIntegration _client;
public Consumer(IDocumentIntegration client)
{
_client = client;
}
public async Task Process(string id)
{
await _client.SubmitDocumentAsync(id);
}
}
以下のように見える?
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "0.3.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="ServiceReference1.IDocumentIntegration")]
public interface IDocumentIntegration
{
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IDocumentIntegration/SubmitDocument", ReplyAction="http://tempuri.org/IDocumentIntegration/SubmitDocumentResponse")]
[System.ServiceModel.FaultContractAttribute(typeof(ServiceReference1.FaultDetail), Action="http://tempuri.org/IDocumentIntegration/SubmitDocumentFaultDetailFault", Name="FaultDetail", Namespace="http://schemas.datacontract.org/2004/07/MyCompany.Framework.Wcf")]
System.Threading.Tasks.Task<string> SubmitDocumentAsync(string documentXml);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "0.3.0.0")]
public interface IDocumentIntegrationChannel : ServiceReference1.IDocumentIntegration, System.ServiceModel.IClientChannel
{
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "0.3.0.0")]
public partial class DocumentIntegrationClient : System.ServiceModel.ClientBase<ServiceReference1.IDocumentIntegration>, ServiceReference1.IDocumentIntegration
{
// constructors and methods here
}
以下のようなインターフェース&クライアント何かを作成 私は& clientCredentialsファクトリメソッドのオーバーロードを使用して登録
public void ConfigureServices(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry(Configuration);
services.AddMvc();
// how do I inject DocumentIntegrationClient here??
var client = new DocumentIntegrationClient();
client.ClientCredentials.UserName.UserName = "myusername";
client.ClientCredentials.UserName.Password = "password";
client.Endpoint.Address = new EndpointAddress(urlbasedonenvironment)
}
AddXxxメソッドのオーバーロードであるファクトリメソッドを使用してみましたか? – Tseng
それは私が思ったものです。 AddScoped ..を使用しようとしていましたが、構文を知りたいですか? – LP13