【发布时间】:2017-08-29 20:12:40
【问题描述】:
好吧,这让我发疯了。我正在将 Amazon SNS 集成到我拥有的 Web 服务中。亚马逊只是向我指定的 url 发送一个包含一堆 json 内容的 HTTP 帖子。我只是无法访问它。
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void HandleBounce()
{
notification = //I need to put the JSON content into here
}
亚马逊只需访问 url (http://test.com/webservice.aspx/HandleBounce)。该方法被正确调用。我只需要获取它在帖子中发送的数据。我该怎么做?
编辑:
我最初尝试使用
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void HandleBounce(string json)
{
notification = //I need to put the JSON content into here
}
但是当我这样做时,根本就不会调用该方法。至少当我删除参数时,该方法是有效的。
编辑 2:
这是亚马逊网站上关于他们向我发送的请求:
POST / HTTP/1.1
x-amz-sns-message-type: SubscriptionConfirmation
x-amz-sns-message-id: 165545c9-2a5c-472c-8df2-7ff2be2b3b1b
x-amz-sns-topic-arn: arn:aws:sns:us-west-2:123456789012:MyTopic
Content-Length: 1336
Content-Type: text/plain; charset=UTF-8
Host: example.com
Connection: Keep-Alive
User-Agent: Amazon Simple Notification Service Agent
{
"Type" : "SubscriptionConfirmation",
"MessageId" : "165545c9-2a5c-472c-8df2-7ff2be2b3b1b",
"Token" : "2336412f37fb687f5d51e6e241d09c805a5a57b30d712f794cc5f6a988666d92768dd60a747ba6f3beb71854e285d6ad02428b09ceece29417f1f02d609c582afbacc99c583a916b9981dd2728f4ae6fdb82efd087cc3b7849e05798d2d2785c03b0879594eeac82c01f235d0e717736",
"TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic",
"Message" : "You have chosen to subscribe to the topic arn:aws:sns:us-west-2:123456789012:MyTopic.\nTo confirm the subscription, visit the SubscribeURL included in this message.",
"SubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:us-west-2:123456789012:MyTopic&Token=2336412f37fb687f5d51e6e241d09c805a5a57b30d712f794cc5f6a988666d92768dd60a747ba6f3beb71854e285d6ad02428b09ceece29417f1f02d609c582afbacc99c583a916b9981dd2728f4ae6fdb82efd087cc3b7849e05798d2d2785c03b0879594eeac82c01f235d0e717736",
"Timestamp" : "2012-04-26T20:45:04.751Z",
"SignatureVersion" : "1",
"Signature" : "EXAMPLEpH+DcEwjAPg8O9mY8dReBSwksfg2S7WKQcikcNKWLQjwu6A4VbeS0QHVCkhRS7fUQvi2egU3N858fiTDN6bkkOxYDVrY0Ad8L10Hs3zH81mtnPk5uvvolIC1CXGu43obcgFxeL3khZl8IKvO61GWB6jI9b5+gLPoBc1Q=",
"SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem"
}
【问题讨论】:
-
让您的方法采用字符串类型的参数并将其命名为 json。调试您的应用程序,让我们知道会发生什么。
-
@Maritim ,我最初尝试这样做但是当我有一个字符串参数时它根本不会调用该方法。不幸的是,由于请求是从亚马逊发送的,我不知道响应是什么,但我想这个参数不是预期的或使用的。
-
您有任何可以检查的请求吗?我怀疑帖子请求的内容类型可能不是您所期望的。
-
@Maritim ,我已将他们发送的假定请求添加到主要问题中。我注意到他们将类型编码为文本,而不是 json。我需要做些不同的事情来处理它吗?
标签: c# asp.net .net web-services