Web services 无法在salesforce中的apex web服务调用中设置标题

Web services 无法在salesforce中的apex web服务调用中设置标题,web-services,amazon-web-services,salesforce,apex-code,Web Services,Amazon Web Services,Salesforce,Apex Code,我目前正在尝试调用Salesforce中的Amazon产品零售Web服务 正如我在书中提到的 起初我无法生成apex存根类,但我遵循@Ballinger建议的方法创建了apex类。我编写了一个apex类来使用该存根并设置请求参数。我写的课程如下 public class AmazonProductStubNew { public static void getResults() { System.Debug(' getResults start '); A

我目前正在尝试调用Salesforce中的Amazon产品零售Web服务

正如我在书中提到的

起初我无法生成apex存根类,但我遵循@Ballinger建议的方法创建了apex类。我编写了一个apex类来使用该存根并设置请求参数。我写的课程如下

public class AmazonProductStubNew
{
 public static void getResults()
 { 
        System.Debug(' getResults start ');
        AmazonWS.AWSECommerceServicePortUS stub = new AmazonWS.AWSECommerceServicePortUS();

        stub.inputHttpHeaders_x = new Map<String,String>();
        stub.inputHttpHeaders_x.put('AWSAccessKeyId','MyAmazonAWSAccessKeyId');
        stub.inputHttpHeaders_x.put('Timestamp','2012-11-28T12:11:30Z');
        stub.inputHttpHeaders_x.put('Signature','Encrypted Secret Code');
        String MarketplaceDomain = '';
        String AWSAccessKeyId = 'MyAmazonAWSAccessKeyId';
        String AssociateTag = '';
        String XMLEscaping = '';
        String Validate = '';
        AmazonWS.ItemSearchRequest Shared = new AmazonWS.ItemSearchRequest();
        Shared.SearchIndex = 'DVD';
        AmazonWS.ItemSearchRequest[] Request = new AmazonWS.ItemSearchRequest[1];
        Request[0] = new AmazonWS.ItemSearchRequest();
        Request[0].Title = 'Inception';
        AmazonWS.ItemSearchResponse_element response = stub.ItemSearch(MarketplaceDomain,AWSAccessKeyId,AssociateTag,XMLEscaping,Validate,Shared,Request);
        AmazonWS.Items_element[] localItems = response.Items;
        System.Debug(localItems[0].TotalResults);
 }
 }
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header />
<env:Body>
<ItemSearch xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
<MarketplaceDomain>
</MarketplaceDomain>
<AWSAccessKeyId>MyAWSAccessKeyId</AWSAccessKeyId>
<AssociateTag></AssociateTag>
<XMLEscaping></XMLEscaping>
<Validate></Validate>
<Shared><SearchIndex>DVD</SearchIndex></Shared>
<Request><Title>Inception</Title>
</Request></ItemSearch>
</env:Body></env:Envelope>
公共类AmazonProductStubNew
{
公共静态void getResults()
{ 
调试('getResults start');
AmazonWS.AWSECommerceServicePortUS存根=新的AmazonWS.AWSECommerceServicePortUS();
stub.inputtpheaders_x=新映射();
stub.inputtpheaders_x.put('AWSAccessKeyId','MyAmazonAWSAccessKeyId');
stub.inputtpheaders_x.put('Timestamp','2012-11-28512:11:30Z');
stub.inputtpheaders_x.put('Signature','Encrypted Secret Code');
字符串MarketplaceDomain='';
字符串AWSAccessKeyId='MyAmazonAWSAccessKeyId';
字符串AssociateTag='';
字符串XMLEscaping='';
字符串验证=“”;
AmazonWS.ItemSearchRequest Shared=新的AmazonWS.ItemSearchRequest();
Shared.SearchIndex='DVD';
AmazonWS.ItemSearchRequest[]请求=新的AmazonWS.ItemSearchRequest[1];
请求[0]=新的AmazonWS.ItemSearchRequest();
请求[0]。标题='Inception';
AmazonWS.itemsearchsresponse_element response=stub.ItemSearch(MarketplaceDomain、AWSAccessKeyId、AssociateTag、XMLEscaping、Validate、Shared、Request);
AmazonWS.Items\u元素[]localItems=response.Items;
调试(本地化项[0].TotalResults);
}
}
尽管我已经向存根添加了HTTP头,但在XML请求消息中并没有得到它 XML请求如下

public class AmazonProductStubNew
{
 public static void getResults()
 { 
        System.Debug(' getResults start ');
        AmazonWS.AWSECommerceServicePortUS stub = new AmazonWS.AWSECommerceServicePortUS();

        stub.inputHttpHeaders_x = new Map<String,String>();
        stub.inputHttpHeaders_x.put('AWSAccessKeyId','MyAmazonAWSAccessKeyId');
        stub.inputHttpHeaders_x.put('Timestamp','2012-11-28T12:11:30Z');
        stub.inputHttpHeaders_x.put('Signature','Encrypted Secret Code');
        String MarketplaceDomain = '';
        String AWSAccessKeyId = 'MyAmazonAWSAccessKeyId';
        String AssociateTag = '';
        String XMLEscaping = '';
        String Validate = '';
        AmazonWS.ItemSearchRequest Shared = new AmazonWS.ItemSearchRequest();
        Shared.SearchIndex = 'DVD';
        AmazonWS.ItemSearchRequest[] Request = new AmazonWS.ItemSearchRequest[1];
        Request[0] = new AmazonWS.ItemSearchRequest();
        Request[0].Title = 'Inception';
        AmazonWS.ItemSearchResponse_element response = stub.ItemSearch(MarketplaceDomain,AWSAccessKeyId,AssociateTag,XMLEscaping,Validate,Shared,Request);
        AmazonWS.Items_element[] localItems = response.Items;
        System.Debug(localItems[0].TotalResults);
 }
 }
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header />
<env:Body>
<ItemSearch xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
<MarketplaceDomain>
</MarketplaceDomain>
<AWSAccessKeyId>MyAWSAccessKeyId</AWSAccessKeyId>
<AssociateTag></AssociateTag>
<XMLEscaping></XMLEscaping>
<Validate></Validate>
<Shared><SearchIndex>DVD</SearchIndex></Shared>
<Request><Title>Inception</Title>
</Request></ItemSearch>
</env:Body></env:Envelope>

设置标题

知道为什么没有添加标题吗

另外,我手动添加了标题并在SOAPUI中进行了尝试,得到了正确的响应


谢谢:)

我认为您使用了错误的函数:)(这个问题确实令人困惑)

SOAP(或通常是HTTP)通信由发送头和实际消息(负载,如果您愿意)组成。标题是短文本内容,消息通常是一个巨大的XML

您的代码正在设置(用于网络通信以进行身份验证、提供有关浏览器的信息、首选语言、设置cookie、返回404页面未找到等状态代码…)请不要对“用于傻瓜”感到不快,但我意识到wikipedia文章有点太多,这可能更简单:

我怀疑亚马逊的Web服务想要的只是
标签中的一些字段?只需检查生成的apex代码是否存在名为“Header”的子类(您也可以搜索“Signature”之类的变量名)。这完全是胡乱猜测,但我认为您必须编写这样的代码:

AmazonWS.AWSECommerceServicePortUS stub = new AmazonWS.AWSECommerceServicePortUS();
AmazonWS.Header h = new AmazonWS.Header();
h.AWSAccessKeyId = 'MyAmazonAWSAccessKeyId';
h.Timestamp = '2012-11-28T12:11:30Z';
h.Signature = 'Encrypted Secret Code';
stub.Header = h; // plug it into the request

// create and plug other required tags
AmazonWS.ItemSearchRequest Shared = new AmazonWS.ItemSearchRequest();
Shared.SearchIndex = 'DVD';
AmazonWS.ItemSearchRequest[] Request = new AmazonWS.ItemSearchRequest[1];
Request[0] = new AmazonWS.ItemSearchRequest();
Request[0].Title = 'Inception';
// ...
现在,为了让它更混乱,您可能仍然需要使用HTTP头,有一个特殊的名为。但一般来说,我相信您是在将数据放在XML中,而不是HTTP头中



有趣的是,我已经从下载了Java示例,如果我读得正确,他们将在URL(端点)中传递签名,而不是在XML中传递。可能是因为它是REST GET方法(如果您可以访问该API,它可以为您节省大量的时间,SOAP是笨重的)。

我认为您使用了错误的函数:)(这个问题确实令人困惑)

SOAP(或通常是HTTP)通信由发送头和实际消息(有效负载,如果您愿意)组成。头是短文本内容,消息通常是一个巨大的XML

您的代码正在设置(用于网络通信以进行身份验证、提供有关浏览器的信息、首选语言、设置cookie、返回404页面未找到等状态代码…)请不要对“用于傻瓜”感到不快,但我意识到wikipedia文章有点太多,这可能更简单:

我怀疑Amazon的webservice想要的只是
标记中的一些字段?只需检查生成的apex代码是否存在名为“Header”的子类(您也可以搜索“Signature”之类的变量名)。这完全是胡乱猜测,但我想您必须这样写:

AmazonWS.AWSECommerceServicePortUS stub = new AmazonWS.AWSECommerceServicePortUS();
AmazonWS.Header h = new AmazonWS.Header();
h.AWSAccessKeyId = 'MyAmazonAWSAccessKeyId';
h.Timestamp = '2012-11-28T12:11:30Z';
h.Signature = 'Encrypted Secret Code';
stub.Header = h; // plug it into the request

// create and plug other required tags
AmazonWS.ItemSearchRequest Shared = new AmazonWS.ItemSearchRequest();
Shared.SearchIndex = 'DVD';
AmazonWS.ItemSearchRequest[] Request = new AmazonWS.ItemSearchRequest[1];
Request[0] = new AmazonWS.ItemSearchRequest();
Request[0].Title = 'Inception';
// ...
现在,为了让它更混乱,您可能仍然需要使用HTTP头,有一个特殊的名为。但一般来说,我相信您是在将数据放在XML中,而不是HTTP头中



有趣的是,我已经从下载了Java示例,如果我读得正确,他们将在URL(端点)中传递签名,而不是在XML中传递签名。可能是因为它是REST GET方法(如果您可以访问该API,它可以为您节省很多时间,SOAP很笨重).

您能澄清一下您的问题吗?标题是关于HTTP头的,但您的问题似乎是关于SOAP消息头的,到底是哪一个?谢谢您的回复:)AWSAccessKeyId、Timestamp、Signature三者都应该存在,以便请求得到处理。在SOAP UI中,在构造请求消息时,我在中指定了它们,它工作得很好。但是当我通过apex类添加时,它并没有像空的那样被添加。我在apex代码中的头设置错误吗?这是我的问题。根据Ape在x教程中,存根有InpAuthttpHeaders_x映射。现在清楚了吗?你能修复你问题的标题吗?完成。删除了HTTP。如果这让人困惑,很抱歉。你能澄清你的问题吗,标题是关于HTTP头的,但你的问题似乎是关于SOAP消息头的,就是它吗?谢谢你的回答:)AWSAccessKeyId,Timestamp,签名这三个签名都应该存在,以便请求得到处理。在SOAP UI中,在构造请求消息时,我在中指定了这三个签名,它工作得很好。但是当我通过apex类添加时,它并没有像空的。apex代码中标题的设置是否错误?这是我的问题。根据Apex教程,