2013-04-25 3 views
16
내가 맥 # 응용 프로그램과 함께이 API를 사용하고자

: 은 (getTransactions이 객체 [] @params를 가져옵니다 내가이 간단한 코드를 작성 내 projcet에 WSDL을 추가 한 후 http://www.affjet.com/2012/11/26/4-4-affjet-api/#more-3099패스 매개 변수 []

나는 몇 가지 방법을 시도했지만 오른쪽 응답을 얻을 couldnt는

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

문자열)을 반환 내가 시도 :

var response = service.getTransactions(new object[] { "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: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> 

당신이 볼 수 있습니다 :이 내가 뭘하려에 대한 응답이었다

<?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; 
} 


?> 

:

와 여기

var response = service.getTransactions(new object[] { "apiKey","******"}); 

는 문서에서 동일한 작업을 수행하는 PHP 코드

API Key not provided 

A 차 응답이 같은 것을해야한다 :

<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> 

내가 제공해야 모두가 "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> 

아이디어가 있으십니까?

+1

은 무엇 당신이 뭘하려 무슨 일이 있었? 문자열을 반환 했습니까? 그 끈은 뭐니? 너는 무엇을 기대 했는가? –

+0

요청한 내용을 편집했습니다. –

+0

service.getTransactions() 메소드의 시그널을 볼 수 있습니까? –

답변

0

PHP의 배열과 C#의 차이점은 문제가있는 것으로 보입니다. PHP에서는 키값 쌍입니다. wdsl에서 생성 된 생성 된 클래스에서 어떻게 보이게합니까? 다음은 귀하의 문제와 관련된 SO 문제의 한 줄입니다. C# equivalent to php associative array 한 가지 대답은 Dictionary<String, String>입니다. 어쩌면 객체 배열로 전달 된 KeyValuePair<String, String>을 사용해 볼 가치가 있습니다.

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

var response = service.getTransactions(new object[] { parm }); 
+0

"skumar"에 쓴 내용을 확인하십시오. 덧글 ... –

+0

@MatanL, 이것은 힘든 것입니다. 나는 이것이 wdsl을 바꾸기 전에 손으로 끓여서 이것으로 작동 할 타입을 만들 수 있도록 도와 줄 것이라고 생각한다 A –

2

중 하나를 다음과 같이 키 값 쌍 클래스 또는 사전 클래스를 사용할 수 있습니다 :이 매혹적인 주제에

 Dictionary<string, string> d = new Dictionary<string, string>(); 
     d.Add("apiKey", "******"); 
     var response = new object[] { d }; 

     KeyValuePair<string, string> d = new KeyValuePair<string, string>("apiKey", "******"); 
     var response = new object[] { d }; 
+0

나는 사전을 이미 시도했다. 나는 지금 keyvalue 쌍둥이를 검사 할 것이다 ... –

+0

{ "The type System. Collections.Generic.KeyValuePair'2 [System.String, mscorlib, 버전 = 4.0.0.0, 문화 = 중립, PublicKeyToken =], [System.String, mscorlib, 버전 = 4.0.0.0, 문화 = 중립, PublicKeyToken =]] XmlInclude 또는 SoapInclude 특성을 사용하여 정적으로 알 수없는 형식을 지정합니다."} –

+0

이것은 예외입니다 ... 피들러가 모든 요청을 캡처하여 내 컴퓨터를 우리에게 보냈습니다 .. –

3

내가 좀 더 깊이 파고 연관 배열 금액 어떤 작업을 말할 필요가있다 .NET SOAP 구현에서의 고통. 연관 배열은 IDictionary (예 : Hashtable)로 표시되지만 직렬화를 거부합니다 (시도해보십시오).

아래 코드는 내가 얻을 수있는 가장 가까운 코드이며, (버그?) .NET 프레임 워크에서는 작동하지 않지만 Mono에서는 작동합니다.모노에서

using System; 
using System.IO; 
using System.Xml; 
using System.Xml.Schema; 
using System.Xml.Serialization; 
using System.Collections.Generic; 
using System.Text; 

public class Test 
{ 
    /* 
    * as per http://stackoverflow.com/a/1072815/2348103 
    */ 
    public class Item 
    { 
    [XmlElement(Form = XmlSchemaForm.Unqualified)] 
    public string key; 

    [XmlElement(Form = XmlSchemaForm.Unqualified)] 
    public string value; 
    } 

    [SoapType(TypeName = "Map", Namespace = "http://xml.apache.org/xml-soap")] 
    public class Map : List<Item> 
    { 
    } 

    public static void Main() 
    { 
    Map map = new Map(); 
    map.Add(new Item { key="foo", value="bar" }); 
    map.Add(new Item { key="quux", value="barf" }); 

    XmlTypeMapping mapping = 
     (new SoapReflectionImporter()).ImportTypeMapping(map.GetType()); 
    XmlSerializer serializer = new XmlSerializer(mapping); 
    XmlTextWriter writer = new XmlTextWriter(System.Console.Out); 
    writer.Formatting = Formatting.Indented; 
    writer.WriteStartElement("root"); 
    serializer.Serialize(writer, map); 
    writer.WriteEndElement(); 
    writer.Close(); 
    } 
} 

/* 
    // 
    // does not work - but see http://msdn.microsoft.com/en-us/magazine/cc164135.aspx 
    // 
    public class Map : IXmlSerializable 
    { 
    const string NS = "http://xml.apache.org/xml-soap"; 
    public IDictionary dictionary; 
    public Map() 
    { 
     dictionary = new Hashtable(); 
    } 

    public Map(IDictionary dictionary) 
    { 
     this.dictionary = dictionary; 
    } 

    public void WriteXml(XmlWriter w) 
    { 
     w.WriteStartElement("Map", NS); 
     foreach (object key in dictionary.Keys) 
     { 
     object value = dictionary[key]; 
     w.WriteStartElement("item", NS); 
     w.WriteElementString("key", NS, key.ToString()); 
     w.WriteElementString("value", NS, value.ToString()); 
     w.WriteEndElement(); 
     } 
     w.WriteEndElement(); 
    } 

    public void ReadXml(XmlReader r) 
    { 
     r.Read(); // move past container 
     r.ReadStartElement("dictionary"); 
     while (r.NodeType != XmlNodeType.EndElement) 
     { 
     r.ReadStartElement("item", NS); 
     string key = r.ReadElementString("key", NS); 
     string value = r.ReadElementString("value", NS); 
     r.ReadEndElement(); 
     r.MoveToContent(); 
     dictionary.Add(key, value); 
     } 
    } 
    public System.Xml.Schema.XmlSchema GetSchema() { return null; } 
    } 
*/ 

샘플 출력 :

<q1:Map xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="id1" d2p1:arrayType="Item[2]" xmlns:d2p1="http://schemas.xmlsoap.org/soap/encoding/" xmlns:q1="http://xml.apache.org/xml-soap"> 
    <Item href="#id2" /> 
    <Item href="#id3" /> 
</q1:Map> 
[...] 

샘플 출력 .NET에서 :

<q1:Array xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="id1" q1:arrayType="Item[2]" xmlns:q1="http://schemas.xmlsoap.org/soap/encoding/"> 
    <Item href="#id2" /> 
    <Item href="#id3" /> 
</q1:Array> 
[...] 
+0

당신의 대답은 제가 지금까지 보아온 것 중 가장 좋은 것입니다 .net에서 작동하지 않습니다 ... 왜 그걸 이해할 수 있다면 ... 당신이 만든 노력에 대해 현상금을 줄 것입니다. 고맙습니다. –