This example assumes your STATICA_URL environment variable is set and contains your unique connection string. 


Here we show how to use Statica to access a SOAP service from a .NET MVC web controller. This example should also apply to other WebRequests made from an MVC controller. 


A common use case is from your MVC controller you want to access an IP-whitelisted service that uses SOAP but the web service object does not have a "proxy" property that allows you to specify the Statica proxy service.


Solution: Create a proxy object and I use it as a property of the WebRequest MVC class, which will send all following requests via the proxy. 


The solution is split in to two parts, the configuration in your web.config (which on Azure can be done from your management console) and the MVC Controller itself. 



MVC Controller

  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Bank.Webservices; // fictitious namespace name for your webservice's reference
using System.Diagnostics;
using System.Xml;
using System.Net;
using System.Web.Configuration;

public class PaymentController : Controller
{
[HttpPost]
// this is usually a form result, so attribute of action is HttpPost
public ActionResult Index(string anyTokenYouUseWithYourBank)
{
string StaticaProxyAddress = WebConfigurationManager.AppSettings["Statica_Proxy_URI"];
// to get the Proxy Uri from Web.config

string StaticaUser = WebConfigurationManager.AppSettings["Statica_User"];
// to get the Proxy User from Web.config

string StaticaPassword = WebConfigurationManager.AppSettings["Statica_Password"];
// to get the Proxy Password from Web.config

var proxy = new WebProxy(StaticaProxyAddress);
// we create a new proxy object

proxy.Credentials = new NetworkCredential(StaticaUser, StaticaPassword);
// we give the proxy the Statica credentials

WebRequest.DefaultWebProxy = proxy;
// thanks to WebRequest, from here on every request of this controller will pass through the proxy

var soapClientObject = new WSBankSoapClient(); //fictitious name for the banks's web service

var result = soapClientObject .GrabSomethingOnTheNet(anyTokenYouUseWithYourBank);
// now our WS call goes passes Proxy and in the variable result we have the web service's result

// we use the result here 

return Redirect("http://newpage");

}
}

  


Configuration (web.config)

The section to add the keys to is <configuration><appSettings> (which you can also directly modify in the Azure Console):

 

 <appSettings>
...
<!-- keys for Statica-->
<add key="Statica_Proxy_URI" value="http://yourStaticaUser:[email protected]:9293"/>
<add key="Statica_User" value="yourStaticaUser"/>
<add key="Statica_Password" value="yourStaticaPassword"/>
<!-- end of keys for Statica-->
...
</appSettings>


This solution was kindly contributed by Riccardo Moschetti, a Microsoft MCSD Web Applications specialist.