gpt4 book ai didi

f# - 将 Amazon 的来自 F# 3.0 的 WSDL Web 服务与类型提供程序一起使用

转载 作者:行者123 更新时间:2023-12-04 05:35:17 25 4
gpt4 key购买 nike

我使用内置 WSDL 类型提供程序编写了以下 F# 3.0 程序来自动生成 Amazon WSDL 的 F# 版本:

open Microsoft.FSharp.Data.TypeProviders

type azn = WsdlService<"http://soap.amazon.com/schemas2/AmazonWebServices.wsdl">

let authorRequest author =
azn.ServiceTypes.AuthorRequest(author=author)

do
let client = azn.GetAmazonSearchPort()
let response = client.AuthorSearchRequest(authorRequest "Harrop")
printfn "%s" response.TotalResults

当我运行它时,我在运行时从 Microsoft 工具堆栈中得到一个令人兴奋的内部异常:
Unhandled Exception: System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (410) Gone. ---> System.Net.WebException: The remote server returned an error: (410) Gone.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
--- End of inner exception stack trace ---

Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Program.azn.ServiceTypes.AmazonSearchPort.AuthorSearchRequest(AuthorRequest AuthorSearchRequest1)
at Program.azn.ServiceTypes.AmazonSearchPortClient.AuthorSearchRequest(AuthorRequest AuthorSearchRequest1)
at Program.azn.ServiceTypes.SimpleDataContextTypes.AmazonSearchPortClient.AuthorSearchRequest(AuthorRequest )
at <StartupCode$ConsoleApplication2>.$Program.main@() in c:\users\jon\documents\visual studio 11\Projects\ConsoleApplication2\ConsoleApplication2\Program.fs:line 5

我后来发现这里有一个更新的模式:
type azn = WsdlService<"http://soap.amazon.com/schemas2/AmazonWebServices.wsdl">

但这并不能解决我令人兴奋的错误消息。有什么问题,我该如何解决?

最佳答案

我不知道端到端的解决方案,但可能可以帮助您更进一步

您现在使用的 URL 对应于 API 的旧版本,我相信最近的一个是 http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl

如果您只是将此 url 传递给 WsdlService 类型提供程序,则在设计时一切都会正常,但在运行时会出现奇怪的错误,例如“序列化消息 ItemSearchRequest1 的正文时出错:'无法生成临时类(结果 = 1 ). 错误 CS0030:无法将类型“Program.Amazon.ServiceTypes.ImageSet[]”转换为“Program.Amazon.ServiceTypes.ImageSet”;错误 CS0029:无法将类型“Program.Amazon.ServiceTypes.ImageSet”隐式转换为“Program.Amazon.ServiceTypes.ImageSet”。 Amazon.ServiceTypes.ImageSet[]'"。

这似乎是已知错误( here ),要修复它,您应该设置 ForceUpdate=false 和 LocalSchemaFile='your local schema file' 然后修复本地架构文件中的 ImagesSet 定义

<xs:element minOccurs="0" maxOccurs="unbounded" name="ImageSets">


<xs:element minOccurs="0" maxOccurs="1" name="ImageSets">

type Amazon = Microsoft.FSharp.Data.TypeProviders.WsdlService<
@"http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl",
ForceUpdate=false,
LocalSchemaFile="amazon.wsdlschema"
>

let searchAuthor author =
Amazon.ServiceTypes.ItemSearch(Request = [| Amazon.ServiceTypes.ItemSearchRequest(Author = author) |])

[<EntryPoint>]
let main argv =
let amazon = Amazon.GetAWSECommerceServicePort()
let result = amazon.ItemSearch (searchAuthor "Harrop")
0

然而,这还不是故事的结束——这段代码抛出 MessageSecurityException:“HTTP 请求被禁止使用客户端身份验证方案‘匿名’”。看起来也是已知问题(即 here ),但要检查解决方案,您需要 Amazon 用户 ID 和 key (我没有)。

关于f# - 将 Amazon 的来自 F# 3.0 的 WSDL Web 服务与类型提供程序一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12027270/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com