传递参数作为对象[]

Mat*_*n L 16 c# soap wsdl web-services affiliate

我希望将此API与ac#应用程序一起使用:http: //www.affjet.com/2012/11/26/4-4-affjet-api/#more-3099

在将wsdl添加到我的projcet后,我写了这个简单的代码:(getTransactions获取一个对象[] @params并返回一个字符串)

Ws_ApiService service = new Ws_ApiService();
string apiKey = "*************";
var response = service.getTransactions(new object[] { apiKey });
Run Code Online (Sandbox Code Playgroud)

我尝试了几种方法,但无法得到正确的答案,我试过:

var response = service.getTransactions(new object[] { "apiKey:****"});
Run Code Online (Sandbox Code Playgroud)

var response = service.getTransactions(new object[] { "apiKey","******"});
Run Code Online (Sandbox Code Playgroud)

这是从他们的文档中做同样的PHP代码:

<?php

$nameSpace = "https://secure.affjet.com/ws/api";

//Creating AffJet client for SOAP
$client = new SoapClient($nameSpace."?wsdl");

$pageNumber = 0;
//Setting up parameters
$params = array();
$params["apiKey"] = "MY_API_KEY";
//Value for parameters (optional)
//$params["networkId"] = array(1,2);
//$params["pageNumber"] = 0;
//$params["pageSize"] = 10;
//Making Request
$response = $client->getNetworks($params);
//XML to SimpleXMLElement Object
$xmlResponse = new SimpleXMLElement($response);
if ($xmlResponse->success == "true"){
    while (isset($xmlResponse->dataList->data)) {
        //Iterate the results
        foreach ($xmlResponse->dataList->data as $data){
            var_dump(xml2array($data));
        }
        //Requesting next page of data
        $pageNumber++;
        $params["pageNumber"] = $pageNumber;
        //Making Request
        $response = $client->getNetworks($params);
        //XML to SimpleXMLElement Object
        $xmlResponse = new SimpleXMLElement($response);
    }
} else {
    //Error somewhere
    echo $xmlResponse->errorMessage;
}

/**
* Transforms the object SimpleXmlElement into an array, easier to handle
*/
function xml2array($xml) {
    $arr = array();
    foreach ($xml as $element) {
        $tag = $element->getName();
        $e = get_object_vars($element);
        if (!empty($e)) {
            $arr[$tag] = $element instanceof SimpleXMLElement ? xml2array($element) : $e;
        } else {
            $arr[$tag] = trim($element);
        }
    }
    return $arr;
}


?>
Run Code Online (Sandbox Code Playgroud)

这是我尝试的回应:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns1="http://secure.affjet.com/ws/api"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
          SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:getTransactionsResponse>
        <return xsi:type="xsd:string">
            &lt;response&gt;&lt;success&gt;false&lt;/success&gt;&lt;errorMessage&gt;
            API Key not provided&lt;/errorMessage&gt;&lt;dataList&gt;
            &lt;/dataList&gt;&lt;/response&gt;
        </return>
        </ns1:getTransactionsResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)

你可以看到:

API Key not provided
Run Code Online (Sandbox Code Playgroud)

响应应该是这样的:

<response>
    <success>true</success>
    <errorMessage></errorMessage>
    <dataList>
        <data>
            <date>2012-11-05 15:02:41</date>//Transaction Date
            <amount>81.67</amount>
            <commission>15.86</commission>
            <status>confirmed</status>//Status, could be: declined, pending, confirmed or paid
            <clickDate></clickDate>
            <ip></ip>
            <custom_id>MyCustomId</custom_id>//Custom Id for the transactions (SID, SubId,clickRef....)
            <unique_id>2548462</unique_id>//Unique Id given from the network to this transaction
            <merchantId>1</merchantId>//Id for the Merchant on AffJet
            <networkId>1</networkId>//Id for the Network on AffJet
        </data>
    </dataList>
</response>
Run Code Online (Sandbox Code Playgroud)

我需要提供的是一个名为"apiKey"的参数及其值

编辑:

在联系他们的支持后,他们说请求应如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                   xmlns:ns1="http://secure.affjet.com/ws/api" 
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                   xmlns:ns2="http://xml.apache.org/xml-soap" 
                   xmlns:SOAP- ENC="http://schemas.xmlsoap.org/soap/encoding/" 
            SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:getTransactions>
            <params xsi:type="ns2:Map">
                <item>
                    <key xsi:type="xsd:string">apiKey</key>
                    <value xsi:type="xsd:string">YOURAPIKEY</value>
                </item>
            </params>
        </ns1:getTransactions>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)

有任何想法吗 ?

Sco*_*ams 0

看来问题是 PHP 和 C# 中数组之间的差异。在 PHP 中,它是一个键值对。他在从 wdsl 创建的生成类中看起来怎么样?这是与您的问题相关的 SO 问题的一行。 C# 相当于 php 关联数组一个答案说尝试一下Dictionary<String, String>。也许值得尝试使用KeyValuePair<String, String>pass 作为对象数组。

KeyValuePair<String, String> parm = new KeyValuePair<String, String>("apiKey","******");

var response = service.getTransactions(new object[] { parm });
Run Code Online (Sandbox Code Playgroud)