2012-03-07 4 views
0

나는 일정 간격으로 데이터베이스를 거쳐 새로운 항목을 3DCarts 데이터베이스에 업데이트/추가하는 응용 프로그램을 만들려고했습니다. 이 코드 예제는 xml 파일의 soap을 사용하여 호출 당 하나의 요청을 보냅니다. 따라서 아이템 정보를 보내기 전에 XML 정보를 생성 할 수 있어야합니다. 이런 XML 파일로는 거의 아무 일도하지 않았기 때문에 필요한 코드 묶음을 작성하여 보낼 방법을 알 수 없습니다. 제안 된 한 가지 방법은 파일을 만들지 만 여전히 실행 중이므로 수많은 항목에 대해 매우 비효율적입니다. 여기에 지금까지C# App으로 3DCart API 설정

sqlStatement = "SELECT * FROM products WHERE name = '" + Convert.ToString(reader.GetValue(0)) + "'"; 
      ServiceReferenceCart.cartAPIAdvancedSoapClient bcsClient = new ServiceReferenceCart.cartAPIAdvancedSoapClient(); 
      ServiceReferenceCart.runQueryResponse bcsResponse = new ServiceReferenceCart.runQueryResponse(); 

      bcsClient.runQuery(storeUrl, userKey, sqlStatement, callBackURL); 
      string result = Convert.ToString(bcsResponse); 

      listBox1.Items.Add(result); 

편집이 무엇을 : 나는 마침내 서비스 참조 설정을 가지고로 현재 코드 블록에 샘플 코드 블록에서 변경되었습니다. 참조에 함수를 사용하는 데는 세부 사항이 없습니다. 이 bcsResponse 함께 그냥 공백입니다 .Body 추가하려고하면 동일한 결과가 있지만 .rtr .Body 추가 할 때 "개체 참조가 개체의 인스턴스로 설정되지 않습니다." 오류. 내가 전에 말했듯이 나는 전에 서비스 레퍼런스를 망쳐 놓지 않았다.

내가 충분히 설명했기를 바란다. 나는 이전에 이런 종류의 일을 정말로하지 않았으며, 매우 실망스러워했다.

도움을 주셔서 감사합니다.

답변

1

나는 실제로 이것으로 놀고 난 후에 이것을 알아내는 것을 끝내었다. 여기에 제가 일할 참조를 얻으려고했던 것이 있습니다. 이전에이 참조를 사용했던 사람이라면 쉽게 이해할 수 있지만 다른 누구에게도이 문제가있을 경우 게시하지 않기로했습니다. SQL은 SELECT/ADD/UPDATE/DELETE 명령문이 될 수 있습니다.이 명령문은 업데이트/추가 전에 sku가 나열되었는지 확인할 수 있습니다.

  //Will be using these multiple times so a variable makes more sense 
      // DO NOT include http:// in the url, also id is not shown in their 
      //database layout pdf they will give but it is the sku/product number 
      string sqlStatement = "SELECT id FROM products WHERE id = '" + Convert.ToString(reader.GetValue(0)) + "')))"; 
      string userKey = "YourKeyHere"; 
      string storeUrl = "YourStoresURLHere"; 

      // Setting up instances from the 3DCart API 
      cartAPIAdvancedSoapClient bcsClient = new cartAPIAdvancedSoapClient(); 
      runQueryRequest bcsRequest = new runQueryRequest(); 
      runQueryResponse bcsResponse = new runQueryResponse(); 
      runQueryResponseBody bcsRespBod = new runQueryResponseBody(); 
      runQueryRequestBody bcsReqBod = new runQueryRequestBody(); 

      //assigning required variables to the requests body 
      bcsReqBod.storeUrl = storeUrl; 
      bcsReqBod.sqlStatement = sqlStatement; 
      bcsReqBod.userKey = userKey; 

      //assigning the body to the request 
      bcsRequest.Body = bcsReqBod; 

      //Setting the response body to be the result 
      bcsRespBod.runQueryResult = bcsClient.runQuery(bcsReqBod.storeUrl, bcsReqBod.userKey, bcsReqBod.sqlStatement, bcsReqBod.callBackURL); 
      bcsResponse.Body = bcsRespBod; 

      //adding the result to a string 
      string result = bcsResponse.Body.runQueryResult.Value; 

      //displaying the string, this for me was more of a test 
      listBox1.Items.Add(result); 

는 또한의 말을 PDF로, 당신은 자신의 저장 및 구매 (자유)에 갈 필요가 당신이 실제 옵션이없는 알 수 있습니다 귀하의 상점에서 고급 API를 활성화하고 기다려야합니다 그것을 활성화하십시오. 이것은 우리에게 약 2 시간이 걸렸다.

+1

이 예제를 이용해 주셔서 감사합니다. 날 잡으려고 3dCart API 예제를 웹에서 찾아 보았습니다. –

+0

아무런 문제도 없었습니다. 내가 작업 할 때 문서 작성이 끔찍했기 때문에 도움이 되었기 때문에 기쁩니다. – Gyouza