2016-08-24 70 views
0

我試圖從瀏覽器訪問WCF服務。我正在從我的瀏覽器發送GET請求到WCF服務。爲了供您參考,WCF服務的細節如下所示。配置來自Nifi的GET請求

服務合同的定義如下:

[ServiceContract] 
    public interface IBZTsoftsensor_WcfService { 

    [OperationContract] 
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "json/?inputModel={inputModel}")] 
     string ExecuteModelJson(string inputModel); 
    } 

而這個接口的實現如下:

public string ExecuteModelJson(string inputModel){ 
    try 
    { 
    BZTsoftsensor_ModelInput input = JsonConvert.DeserializeObject<BZTsoftsensor_ModelInput>(inputModel); 
    var results = this.ExecuteModel(input); 
    return JsonConvert.SerializeObject(results); 
    } 
    catch (Exception ex) 
    { 
    return ex.Message; 
    } 
} 

當我從瀏覽器訪問該WCF服務與網址

http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/json/?inputModel={"Pyro":"30.0","O2":"20.0"} 

我的WCF服務正在成功響應。

但是,使用上述URL,當我配置GeTHTTP Nifi處理器時,處理器正在對GET請求URL中的非法字符進行錯誤處理。

您能否告訴我 - 在使用GetHTTP處理器時,我必須在GET URL中做出什麼改變?

回答

2

您可能需要編碼您inputModel參數,你可以使用NiFi表達式語言的URLEncode的方法:

https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html#urlencode

嘗試以此爲URL屬性:

http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/json/?inputModel= $ {文字( 「{\」Pyro \「:\」30.0 \「,\」O2 \「:\」20.0 \「}」):urlEncode()}

或者,因爲您的網址已修復,您可以使用online encoding tool,它給出了這樣的事情:

http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/json/?inputModel=%7B%22Pyro%22%3A%2230.0%22%2C%22O2%22%3A%2220.0%22%7D%20

+0

感謝您的指示。我對Nifi有點新鮮感。你能否建議我 - 我應該如何使用表達式語言。什麼是GetHTTP處理器的URL屬性值? – Pankesh

+0

感謝您的指點。它現在有效! :) – Pankesh