Avoid calling the web service to debug asp.net application with sample data

0

I have an Asp.Net application in VisualStudio 2013 and SQL Server 2014 and I need to debug it without calling the web service and return a test number to me as proof and tell me that the invoice is paid.
Here I have the debugging enabled:

<compilation debug="true" targetFramework="4.5">
  <assemblies>
    <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
    <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
  </assemblies>
</compilation>

Here I have the web service:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="ServiceSoap" maxReceivedMessageSize="2147483647">
      <security mode="Transport" />
    </binding>
    <binding name="ServiceSoap1" maxReceivedMessageSize="2147483647" />
  </basicHttpBinding>
</bindings>
<client> 
  <endpoint address="https:MiWebService.asmx" binding="basicHttpBinding" bindingConfiguration="ServiceSoap" contract="ContractWebService" name="ServiceSoap" />
</client>


What I thought was to set some variable that enables or disables the web service and can hardcode the data I need (to return an invoice number and other information that tells me that it is paid for example)

    
asked by Pablo Matias 26.04.2018 в 15:27
source

1 answer

0

I'll put it here:

interface IWebService
{
    string devuelveFactura();
    bool estaPagada();
}

Now at your service you make it inherit from this:

class WebService: IWebService{
    string devuelveFactura() {....} 
}

You create a class to simulate the fake web service False Web service

class WebServiceFalso: IWebService{
    string devuelveFactura() {....} 
}

Where you are going to use the webservice because you simply do this

   IWebService webFalso = new WebServiceFalso();

Now where are you going to use this webservice? Do you pass it by parameter or do you call it directly?

In the case that you pass it by parameter to some function it would be:

public void obtenerFactura(IWebService webService){ .....}

You can see that the function receives an interface as parameter, so it does not know if the object is of the WebService or WebServiceFalse class, and you only have to call the methods defined in the interface.

I hope you're worth the explanation

    
answered by 26.04.2018 / 17:24
source