当前位置: 首页 > 知识库问答 >
问题:

从API管理服务调用CosmosDB的存储过程

孟意致
2023-03-14

我希望API管理服务中的一个API调用CosmosDB中的存储过程并返回其结果。似乎没有太多关于这个主题的文件。

到目前为止我的尝试:

    null
<policies>
    <inbound>
        <base />
        <set-variable name="Content-Type" value="application/query+json" />
        <set-variable name="x-ms-documentdb-isquery" value="True" />
        <set-variable name="x-ms-documentdb-query-enablecrosspartition" value="False" />
        <set-variable name="x-ms-max-item-count" value="1000" />
        <set-variable name="x-ms-version" value="2017-02-22" />
        <set-variable name="x-ms-date" value="@( DateTime.UtcNow.ToString("R") )" />
        <set-header name="Content-Type" exists-action="override">
            <value>@((string)context.Variables["Content-Type"])</value>
        </set-header>
        <set-header name="x-ms-documentdb-isquery" exists-action="override">
            <value>@((string)context.Variables["x-ms-documentdb-isquery"])</value>
        </set-header>
        <set-header name="x-ms-documentdb-query-enablecrosspartition" exists-action="override">
            <value>@((string)context.Variables["x-ms-documentdb-query-enablecrosspartition"])</value>
        </set-header>
        <set-header name="x-ms-max-item-count" exists-action="override">
            <value>@((string)context.Variables["x-ms-max-item-count"])</value>
        </set-header>
        <set-header name="x-ms-version" exists-action="override">
            <value>@((string)context.Variables["x-ms-version"])</value>
        </set-header>
        <set-header name="x-ms-documentdb-partitionkey" exists-action="override">
            <value>@("[\""+context.Subscription.Id+"\"]")</value>
        </set-header>
        <set-header name="x-ms-date" exists-action="override">
            <value>@( (string)context.Variables["x-ms-date"] )</value>
        </set-header>
        <set-variable name="StringToSign" value="@(string.Format("post\nsprocs\ndbs/{myDBName}/colls/{myCollName}\n{0}\n\n", ((string)context.Variables["x-ms-date"]).ToLowerInvariant()))" />
        <set-variable name="cosmosreadwritekey" value="{{MyMasterKeyInReadWriteMode}}" />
        <set-variable name="SharedKey" value="@{
            // https://docs.microsoft.com/en-us/rest/api/documentdb/access-control-on-documentdb-resources#constructkeytoken
            System.Security.Cryptography.HMACSHA256 hasher = new System.Security.Cryptography.HMACSHA256(Convert.FromBase64String((string)context.Variables["cosmosreadwritekey"]));
            return Convert.ToBase64String(hasher.ComputeHash(System.Text.Encoding.UTF8.GetBytes((string)context.Variables["StringToSign"])));
        }" />
        <set-variable name="Authorization" value="@(string.Format("type=master&ver=1.0&sig={0}", ((string)context.Variables["SharedKey"]).Replace("&","%26").Replace("+","%2B").Replace("=","%3D")))" />
        <set-header name="Authorization" exists-action="override">
            <value>@((string)context.Variables["Authorization"])</value>
        </set-header>
        <set-backend-service base-url="https://{myCosmosName}.documents.azure.com" />
        <rewrite-uri template="/dbs/{myDBName}/colls/{myCollName}/sprocs" />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>
    null
    null

共有1个答案

谢和同
2023-03-14

对于发送参数,请看一下这个。看起来设置授权令牌有问题,请参考这个。

 类似资料:
  • 我在SAP HANA中定义了一个存储过程,其中包含3个in参数,返回一个记录集。当我用语法调用它时,它在HANA studio中运行得非常好。 现在我需要从微软SQL服务器调用它(我在2016年)。我有一个与HANA服务器的远程链接服务器连接,当使用和语法查询表和视图时,它可以正常工作。 我尽力了,但找不到调用远程过程的方法。“CALL sp_name(p,p,p)”语法返回“对象没有列或当前用户

  • 这里的console.log(doc2)也没有显示我想要的删除元素。

  • 我正在使用Spring Framework进行数据库调用。我有一个更新,涉及调用2个存储过程,每个过程都在执行多个操作。 我在每个SP中分别定义了以下事务管理: 如果我单独调用每个SP,这可以正常工作,但我想在一个事务中完成整个操作,因此如果对第一个SP的调用有效,但对第二个SP的调用失败,它会同时回滚两者。 所以很明显,我需要从sps中删除提交并在Spring端处理它。 目前对于Spring,我

  • 问题内容: 是否有人从Oracle存储过程成功访问了Web服务?如果是这样,那是Java存储过程吗?PL / SQL存储过程? 有什么原因为什么我不应该尝试从存储的proc访问WS? 这是我到目前为止发现的几个参考 数据库Web服务 从Java存储过程调用外部Web服务 为了澄清,这是针对SOAP调用的 问题答案: 首先,您要调用哪种Web服务?我假设是SOAP或REST。 对于REST Web服

  • 问题内容: 我正在编写一个简单的Web应用程序以调用存储过程并检索一些数据。它是一个非常简单的应用程序,可以与客户的数据库进行交互。我们传递员工ID和公司ID,存储过程将返回员工详细信息。 Web应用程序无法更新/删除数据,并且正在使用SQL Server。 我正在Jboss AS中部署Web应用程序。我应该使用JPA访问存储过程还是。在这种情况下使用JPA的任何优势。 调用该存储过程的sql语句

  • 问题内容: 当我使用JNI方法构建Java对象时,为了将其作为参数传递给我使用JNI调用API进行调用的Java方法,如何管理它的内存? 这是我正在处理的内容: 我有一个C对象,该对象的析构函数要复杂得多。这个C对象将与Java对象相关联,一旦应用程序完成了Java对象,我将不再需要C对象。 我正在这样创建Java对象(为了清楚起见,省略了错误检查): 那么,既然我已经完成了,该怎么办?理想情况下