简体   繁体   中英

F# Odata service type provider through http proxy

I want to use odata type provider but it causes next error while compiling: (407) proxy authentication required . There are no errors at design time. Does anybody know how to set the proxy in type provider? Sample code:

open Microsoft.FSharp.Data.TypeProviders
type db = ODataService<"http://ebayodata.cloudapp.net/">
[<EntryPoint>]
     let main argv=
           let eBay = db.GetDataContext()
           0

This blog posting mentions some sample code which may cover proxies.

The Freebase type provider can be used with .NET 3.5, .NET 4.0, .NET 4.5, Silverlight and Portable programming. A proxy may be needed in some cases. The projects in Tests\\ProjectsUsingTypeProvider.sln show some sample libraries for these different cases.

You might wish to look at this file specifically as well.

Try to specify a default web proxy as follows:

open System.Net // for WebProxy etc.
open Microsoft.FSharp.Data.TypeProviders

// put here actual proxy address
let proxy = new WebProxy("http://192.168.1.1:3128") :> IWebProxy
// put here your credentials if needed
proxy.Credentials <- NetworkCredential("proxy_user", "password")
// set up a default proxy
WebRequest.DefaultWebProxy <- proxy

// here the default proxy will be used
type db = ODataService<"http://ebayodata.cloudapp.net/">

Or you can try to use a proxy which was specified in IE as follows:

WebRequest.DefaultWebProxy <- WebRequest.GetSystemWebProxy()
WebRequest.DefaultWebProxy.Credentials <- CredentialCache.DefaultNetworkCredentials

If you have an error while compiling then this is probably because of F# compiler (Fsc.exe) can't connect to the proxy server. You can fix this by modifying Fsc.exe.config , just add the following text under the configuration section:

  <system.net>
    <defaultProxy useDefaultCredentials="true" />    
  </system.net>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM