2016-09-01 1 views
3

SOAP 웹 서비스에서 일부 데이터를 가져 오기 위해 JavaScript HTTP 어댑터를 사용하려고합니다. 이를 위해 Type8과 함께 MFP8과 Ionic을 사용하고 있습니다. MobileFirst 8 용 JS HTTP 어댑터에 메서드 추가

나는 다음과 같은 어댑터 구현 파일, 여기

function getFeed(params) { 
    var sr = 
      "<soapenv:Envelope " + 
      "xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " + 
      "xmlns:len=\"targetNamespace HERE" >" + 
      "<soapenv:Header/>"+ 
      "<soapenv:Body>" + 
      "<len:authentication>" + 
      "<username>"+params[0]+"</username>"+ 
      "<password>"+params[1]+"</password>"+ 
      "</authentication></soapenv:Body></soapenv:Envelope>"; 

    var input = { 
     method : 'post', 
     returnedContentType : 'xml', 
     path : 'PATH HERE', 
     body: { 
      content: sr, 
      contentType: 'text/xml; charset=utf-8', 
      }, 
    }; 
    return MFP.Server.invokeHttp(input); 
} 

그리고는 adapter.xml이다가,

<mfp:adapter name="http" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:mfp="http://www.ibm.com/mfp/integration" 
      xmlns:http="http://www.ibm.com/mfp/integration/http"> 
    <displayName>http</displayName> 
    <description>http</description> 
    <connectivity> 
     <connectionPolicy xsi:type="http:HTTPConnectionPolicyType"> 
      <protocol>http</protocol> 
     <domain>DOMAIN NAME HERE</domain> 
     <port>PORT NO HERE</port> 
      <connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds> 
      <socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds> 
      <maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode> 
     </connectionPolicy> 
    </connectivity> 
    <procedure name="getFeed"/> 
</mfp:adapter> 

그래서, API 문서를 다음, 나는 내 어댑터를 호출하려면 다음을했다 내 이온 공급자,

var resourceRequest = new WLResourceRequest("adapters/http/getFeed", WLResourceRequest.GET); 
    resourceRequest.setQueryParameter("params", "['username', 'password']"); 
    resourceRequest.send().then(
     function(response) { 
      alert('response '+JSON.stringify(response.responseText)); 
     }, 
     function(response) { 
      alert("HTTP Failure "+JSON.stringify(response)); 
     } 
    ); 

SOAP 서비스에서 특정 데이터를 가져와야하기 때문에 이자형. 이를 위해서는 매개 변수와 메서드를 전달해야합니다.

지식 센터에서 필자는 쿼리 문자열을 사용하여 매개 변수를 호출하는 방법을 찾았습니다. 매개 변수를 전달할 수 있습니다.

내 요구 사항은 메서드 이름도 전달하는 것입니다.

누구든지 메소드 이름을 전달하는 방법을 알려 줄 수 있습니까?

아무도 감사드립니다.

답변

2

당신이 원하는대로 당신은 같은 것을 할 수있는 예를 들어 당신은 많은 매개 변수를 전달할 수 있습니다 : 어댑터에

을 :

function getFeed(method, username, password) { 
    var sr = 
      "<soapenv:Envelope " + 
      "xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " + 
      "xmlns:len=\"targetNamespace HERE" >" + 
      "<soapenv:Header/>"+ 
      "<soapenv:Body>" + 
      "<len:authentication>" + 
      "<method>"+method+"</method>"+ 
      "<username>"+username+"</username>"+ 
      "<password>"+password+"</password>"+ 
      "</authentication></soapenv:Body></soapenv:Envelope>"; 

    var input = { 
     method : 'post', 
     returnedContentType : 'xml', 
     path : 'PATH HERE', 
     body: { 
      content: sr, 
      contentType: 'text/xml; charset=utf-8', 
      }, 
    }; 
    return MFP.Server.invokeHttp(input); 
} 

와 클라이언트에서 :

var resourceRequest = new WLResourceRequest("adapters/http/getFeed", WLResourceRequest.GET); 
    resourceRequest.setQueryParameter("params", "['myMethod', 'myUsername', 'myPassword']"); 
    resourceRequest.send().then(
     function(response) { 
      alert('response '+JSON.stringify(response.responseText)); 
     }, 
     function(response) { 
      alert("HTTP Failure "+JSON.stringify(response)); 
     } 
    ); 

요청의 JSON 배열 구문은 매개 변수가 네트워크를 통해 전달되는 방식 일 뿐이며 어댑터에서 배열을 다시 가져 오는 것은 아닙니다. 배열의 첫 번째 요소를 첫 번째 함수 매개 변수에 할당하고 두 번째 요소를 두 번째 매개 변수에 할당하여 작동합니다.

+0

나는 그걸 시도했습니다. 나는 방법을 얻을 수 없습니다 –

+1

예! 이제 작동 중입니다. 고맙습니다. –

관련 문제