accessing multi endpoints web services (ASMX) best practices in c#

Dicekey

I have a clean architecture project that provide micro services, one of which is to access Agresso ERP web services.

https://***************/service.svc

it provide many services

  • https://**/service.svc?FooService/Foo
  • https://**/service.svc?BooService/Boo

each of which has it's own service reference(connected service), and each of which has many methods.

each call to any of the end point you need to pass credentials with it.

        var fooSoapClient = new FooSoapClient();
        var credentials = new WSCredentials
        {
            Username = "fakeuser",
            Password = "fakepassword",
            Client = "fakeclient",
        };
        var result =  fooSoapClient.GetFoosAsync(Foo filter,true,
                      credentials ); 

(P.S) credential class exist in all entities

namespace Foo1NS
{
  public partial class WSCredentials : object
  {
     public string Username {get;set;}

     public string Client {get;set;}

     public string Password {get;set;}
  }
}


 namespace Foo2NS
{
  public partial class WSCredentials : object
  {
     public string Username {get;set;}

     public string Client {get;set;}

     public string Password {get;set;}
  }
}

i can access all end points with no problem.

I have the following Questions:

  • Is there a generic solution i can follow for not to Fall in DRY?
  • is there a design pattern that best target this issue?
raterus

Here is what I've done in the past, it fits in well into Dependency Injection/containers if you use that as well. The key thing here is to define an single interface that all services will implement. Your code that uses this should only be using the interface.

Each class should implement an interface you define, e.g. IWebServiceOperations

public interface IWebServiceOperations
{
    WebServiceOperationResult GetFooAsync(WebServiceOperationRequest request);
}

I'll leave you to figure out the classes WebServiceOperationResult/Request, they just hold your request/response variables, including credentials.

Then each webservice you need to implement is done in a separate class. You also dictate in the constructor what type of implementation this is (FooSoap1 vs FooSoap2) e.g.

public class FooSoapClient : BaseClient, IWebServiceOperations
{  
    public FooSoapClient() : base(Clients.FooSoap1) 

    public GetFooAsync(...)
    {
         ...
    }  
}

public class BaseClient
{
    private readonly eFooServiceType _serviceType;
    public eFooServiceType ServiceType {
        get{
            return _serviceType;
        }
    }

    protected BaseClient(eFooServiceType service)
    {
        _serviceType = service;
    }
}

Now you should have a bunch of class references. Either your DI container can resolve these for you, based on the service type you want, or you could add them to a Dictionary, so if you wanted to operate against FooSoap1, you'd do...

var fooSoapClient1 = myServices[Clients.FooSoap1];
await fooSoapClient1.GetFooAsync(...)

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Audio synthesis best practices

분류에서Dev

How to call web Services in C#

분류에서Dev

Gatsbyjs Page generation | Best practices

분류에서Dev

Rails best practices of using layouts

분류에서Dev

Accessing Docker Services from Host

분류에서Dev

best approach and practices to handle exceptions in Spring?

분류에서Dev

Best practices on using sudo in a bash script

분류에서Dev

Passing Fragment some variable best practices

분류에서Dev

Best practices Boolean vs Integer in SQL

분류에서Dev

Repository pattern interfaces- Best practices?

분류에서Dev

What are the best practices for including CSS and JavaScript in a page?

분류에서Dev

Best practices for installing ubuntu alongside Windows 10

분류에서Dev

RESTful web services in java

분류에서Dev

Javascript: Accessing multi-dimensional object properties

분류에서Dev

Accessing elements in a multi-channel OpenCV Mat

분류에서Dev

Best practices to benchmark deep models on CPU (and not GPU) in PyTorch?

분류에서Dev

How to write to Excel using MVC and EF Code First - Best Practices

분류에서Dev

How to write to Excel using MVC and EF Code First - Best Practices

분류에서Dev

node.js & express - global modules & best practices for application structure

분류에서Dev

Best practices for keeping EC2 Ubuntu machines updated

분류에서Dev

angularjs service calling $location.path is it against best practices?

분류에서Dev

Web Edition의 Analysis Services

분류에서Dev

Securing Web API web services, windows authentication

분류에서Dev

For Grails, Optimizing Controller to Services invocation in relation to sharing data and accessing the database

분류에서Dev

TFS http : // localhost : 8080 / Services / V1.0 / ServerStatus.asmx를 사용할 수 없습니다.

분류에서Dev

How best to deploy this multi-tier app?

분류에서Dev

Best Linux for a small Web server

분류에서Dev

External jar available to all Jetty web services

분류에서Dev

Asp.net web api services

Related 관련 기사

  1. 1

    Audio synthesis best practices

  2. 2

    How to call web Services in C#

  3. 3

    Gatsbyjs Page generation | Best practices

  4. 4

    Rails best practices of using layouts

  5. 5

    Accessing Docker Services from Host

  6. 6

    best approach and practices to handle exceptions in Spring?

  7. 7

    Best practices on using sudo in a bash script

  8. 8

    Passing Fragment some variable best practices

  9. 9

    Best practices Boolean vs Integer in SQL

  10. 10

    Repository pattern interfaces- Best practices?

  11. 11

    What are the best practices for including CSS and JavaScript in a page?

  12. 12

    Best practices for installing ubuntu alongside Windows 10

  13. 13

    RESTful web services in java

  14. 14

    Javascript: Accessing multi-dimensional object properties

  15. 15

    Accessing elements in a multi-channel OpenCV Mat

  16. 16

    Best practices to benchmark deep models on CPU (and not GPU) in PyTorch?

  17. 17

    How to write to Excel using MVC and EF Code First - Best Practices

  18. 18

    How to write to Excel using MVC and EF Code First - Best Practices

  19. 19

    node.js & express - global modules & best practices for application structure

  20. 20

    Best practices for keeping EC2 Ubuntu machines updated

  21. 21

    angularjs service calling $location.path is it against best practices?

  22. 22

    Web Edition의 Analysis Services

  23. 23

    Securing Web API web services, windows authentication

  24. 24

    For Grails, Optimizing Controller to Services invocation in relation to sharing data and accessing the database

  25. 25

    TFS http : // localhost : 8080 / Services / V1.0 / ServerStatus.asmx를 사용할 수 없습니다.

  26. 26

    How best to deploy this multi-tier app?

  27. 27

    Best Linux for a small Web server

  28. 28

    External jar available to all Jetty web services

  29. 29

    Asp.net web api services

뜨겁다태그

보관