2

我使用内置的 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">

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

4

1 回答 1

3

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

您现在使用的 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[]' "。

这似乎是已知错误(此处),要修复它,您应该设置 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 请求被客户端身份验证方案‘匿名’禁止”。它看起来也是已知问题(即此处),但要检查解决方案,您需要 Amazon 用户 ID 和密钥(我没有)。

于 2012-08-19T16:03:46.877 回答