Issue
I have a xamarin android app and when I try download an image from my MVC site hosted on local IIS
it fails.
Firewall is off and within genymotion emulator I can see file on the OS browser, but when I download the file through my xamarin app an Exception occurs : NameResolutionFailureException.
android permission on access Internet is set
using (var webClient = new WebClient())
{
var imageByte = webClient.DownloadData("http://10.0.3.2/imgs/1.jpg");
}
Solution
You might need to open the firewall on your PC to accept a remote connection from the IP that your emulator has (use adb shell ifconfig
as SushiHangover suggests to see the ip address of your emulator)
To set up a firewall rule to allow a remote connection, see this guide (it's about WCF, but adding the firewall rules should be the same regardless of the service technology used): https://developer.xamarin.com/guides/cross-platform/application_fundamentals/web_services/walkthrough_working_with_WCF/#Configuring_Remote_Access_to_IIS_Express
Relevant bits (edited to take out references to WCF):
Configure IIS Express to Accept Remote connections - This step involves editing the config file for IIS Express to accept remote connections on a specific port and then setting up a rule for IIS Express to accept the incoming traffic.
Add an Exception to Windows Firewall - We must open up a port through Windows Firewall that remote applications can use. You will need to know the IP address of your workstation. For the purposes of this example we'll assume that our workstation has the IP address 192.168.1.143.
Let's begin by configuring IIS Express to listen for external requests. We can do this by editing the configuration file for IIS Express at [solutiondirectory].vs\config\applicationhost.config, as shown in the following screenshot: Locate the site element with the name of your service. It should look something like the following XML snippet:
<site name="HelloWorldWcfHost" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="\\vmware-host\Shared Folders\tom\work\xamarin\code\private-samples\webservices\HelloWorld\HelloWorldWcfHost" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:9607:localhost" />
</bindings>
</site>
We will need to add another binding to open up port 9608 to outside traffic. Add the following XML to the bindings element, replacing the IP address with your own IP address:
<binding protocol="http" bindingInformation="*:9608:192.168.1.143" />
This will configure IIS Express to accept HTTP traffic from any remote IP address on port 9608 on the external IP address of the computer. This above snippet assumes the IP address of the computer running IIS Express is 192.168.1.143. After the changes, the bindings element should look like the following:
<site name="HelloWorldWcfHost" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="\\vmware-host\Shared Folders\tom\work\xamarin\code\private-samples\webservices\HelloWorld\HelloWorldWcfHost" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:9607:localhost" />
<binding protocol="http" bindingInformation="*:9608:192.168.1.143" />
</bindings>
</site>
Next, we need to configure IIS Express accept incoming connections on port 9608. Startup up an administrative command prompt, and run this command:
netsh http add urlacl url=http://192.168.1.143:9608/ user=everyone
The final step is to configure Windows Firewall to permit external traffic on port 9608. From an administrative command prompt, run the following command:
netsh advfirewall firewall add rule name="IISExpressXamarin" dir=in protocol=tcp localport=9608 profile=private remoteip=localsubnet action=allow
This command will allow incoming traffic on port 9608 from all devices on the same subnet as the Windows 10 workstation.
Answered By - jgoldberger - MSFT
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.