Asp.net web api 我无法在本地主机上为Android仿真器使用类型提供程序

Asp.net web api 我无法在本地主机上为Android仿真器使用类型提供程序,asp.net-web-api,xamarin,f#,type-providers,Asp.net Web Api,Xamarin,F#,Type Providers,我无法在本地主机上为Android仿真器使用类型提供程序 在使用F#的类型提供程序时,这对我不起作用,因为类型提供程序在设计时建立了连接 当我使用localhost时,类型提供程序很高兴 [<Literal>] let JsonPath = "http://localhost:48213/api/cars" type Repository = JsonProvider<JsonPath> [] 让JsonPath=”http://localhost:48213/ap

我无法在本地主机上为Android仿真器使用类型提供程序

在使用F#的类型提供程序时,这对我不起作用,因为类型提供程序在设计时建立了连接

当我使用localhost时,类型提供程序很高兴

[<Literal>]
let JsonPath =   "http://localhost:48213/api/cars"
type Repository = JsonProvider<JsonPath>
[]
让JsonPath=”http://localhost:48213/api/cars"
类型Repository=JsonProvider
但是,在尝试使用localhost路径时,我收到一个被拒绝的连接。可以找到有关此错误的详细信息

因此,我认为解决方案是使用替代IP地址:

当我使用10.0.2.2时,类型提供程序不满意

将IP地址上的“localhost”替换为“10.0.2.2”会导致编译错误,原因是TypeProvider未建立到更新IP地址的连接

当我尝试使用“10.0.2.2”作为替代IP(又名:变通方法)时,以下代码将不会编译,这是emulator工作所需的IP:

[<Literal>]      (* "10.0.2.2" is the workaround IP for local host *)
let JsonPath =   "http://10.0.2.2:48213/api/cars"
type Repository = JsonProvider<JsonPath>

type Car = { Make:string ; Model:string }

let getCars() =

    Repository.Load JsonPath
    |> Array.toSeq
    |> Seq.map(fun x -> { Make=x.Make ; Model=x.Model })
[](*“10.0.2.2”是本地主机的解决方案IP*)
让JsonPath=”http://10.0.2.2:48213/api/cars"
类型Repository=JsonProvider
类型Car={Make:string;Model:string}
让我们来看看汽车=
加载JsonPath
|>Array.toSeq
|>Seq.map(funx->{Make=x.Make;Model=x.Model})

总之,如何通过本地运行的WebAPI服务访问文件,并且在模拟器上执行类型提供程序时仍能让类型提供程序满意?

创建
JsonProvider
时提供的静态参数纯粹是为了在设计时生成类型。调用
Repositor.Load
时,这将是运行时使用的uri。它们应该分开处理,如下所示:

[<Literal>]
let DevelopmentJsonPath =   "http://localhost:48213/api/cars"

type Repository = JsonProvider<DevelopmentJsonPath>

type Car = { Make:string ; Model:string }

let runtimeUri = "http://production.mycompany.com/api/cars"
let getCars() =

    Repository.Load runtimeUri
    |> Array.toSeq
    |> Seq.map(fun x -> { Make=x.Make ; Model=x.Model })
[]
让开发JSONPATH=”http://localhost:48213/api/cars"
类型Repository=JsonProvider
类型Car={Make:string;Model:string}
让runtimeUri=”http://production.mycompany.com/api/cars"
让我们来看看汽车=
加载运行时URI
|>Array.toSeq
|>Seq.map(funx->{Make=x.Make;Model=x.Model})

谢谢你,斯图尔特。然而,当插入“10.0.2.2”时,编译器在设计时会抱怨。因此,我认为直到emulator启动,IP才存在。我将其向后设置为=),因此如果您使用localhost使类型提供程序工作并编译。然后将
runtimeUri
设置为运行时所需的值。谢谢。我遇到了另一个问题,我的屏幕完全变黑,没有数据。但这是另一个问题。