2016-08-24 68 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