You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using ServiceToController;
...
...
...
public class Startup
{
...
...
public void ConfigureServices(IServiceCollection services){
...
...
var builder = services.AddControllersWithViews().AddControllersAsServices();
builder.AddCastedService<MyService>();}
...
...}publicclassMyService{publicTask<MyObject>GetAll(MyObjectobj){return Task.FromResult(obj);}}publicclassMyObject{publicstringName{get;set;}}
Sample3 - Wcf Auto Generated Proxy Service From WSDL To Controller
using ServiceToController;
...
...
...
public class Startup
{
...
...
public void ConfigureServices(IServiceCollection services){
...
...
var builder = services.AddControllersWithViews().AddControllersAsServices();
builder.AddCastedService(newCastOptions<WcfAutoGeneratedClient>{AddTestMethod=false,ApiPath="/api/WcfToRest",UseNewInstanceEveryMethod=true,CustomClassName="WcfToRestController",MethodNameRefactor=name => name.Replace("Async",""),MethodFilter=(x =>!x.Name.Contains("OpenAsync")&&!x.Name.Contains("CloseAsync")&& x.Name.Contains("Async")&& x.IsPublic &&(x.ReturnType ==typeof(Task)||(x.ReturnType.IsGenericType && x.ReturnType.GetGenericTypeDefinition()==typeof(Task<>)))),CreateInstanceFunc=type =>(WcfAutoGeneratedClient)Activator.CreateInstance(type,null, remoteAddress),BeforeMethod=(client)=>{try{ client.ClientCredentials.ServiceCertificate.SslCertificateAuthentication =new X509ServiceCertificateAuthentication(){CertificateValidationMode= X509CertificateValidationMode.None,RevocationMode= System.Security.Cryptography.X509Certificates.X509RevocationMode.NoCheck};if(remoteAddress.Contains("https")){ client.ClientCredentials.UserName.UserName ="WS_USERNAME"; client.ClientCredentials.UserName.Password ="WS_PASSWORD";} client.OpenAsync().Wait();}catch{}},AfterMethod=(client,res)=>{try{ client.Close();}catch{}returnres;}});}
...
...}