有人能告诉我,如果Colfusion 8可以消耗WCF服务? [英] Can someone tell me if Colfusion 8 can consume a WCF service?

查看:360
本文介绍了有人能告诉我,如果Colfusion 8可以消耗WCF服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



此外,WCF服务使用的Entity Framework 6.0应该返回大的JSON结构。
现在我只是想找一个简单的例子,可以调用一个简单的WCF服务:

  [ServiceContract] 
public interface ITest
{
[OperationContract(Name =Test_GetDate)]
[WebGet(UriTemplate =/ GetDate,RequestFormat = WebMessageFormat.Json,ResponseFormat = WebMessageFormat。 Json)]
string GetDate();
...

public class Test:ITest
{
public string GetDate()
{
return(DateTime.UtcNow.ToString ());
}
...

谢谢

解决方案

是的,可以。这个场景对我有用,但是我使用的是XML格式(WCF SOAP)不是rest / json,但是你可以尝试。



肥皂信封应该看起来像。此工具是免费的 http://www.soapui.org/ ,很容易使用。



- 创建新Soap UI项目并在输入中粘贴WSDL地址,应用程序将生成空XML请求 - soap信封。



- 您可以通过此应用程序测试您的服务



- 我使用cfhttp从cf:

调用服务



我们想出了肥皂信封,我们把它放在cf变量中:

 < cfsavecontent variable =soapBody> 

< soapenv:Envelope xmlns:soapenv =http://schemas.xmlsoap.org/soap/envelope/xmlns:tem =http://tempuri.org/xmlns:ozon =http://schemas.datacontract.org/blah/prc>
< soapenv:Header />
< soapenv:Body>
< tem:myservicemethod>
< tem:someParameter1>这是我的第一个参数< / tem:someParameter1>
< tem:someParameter2>
< blah:AC>这是我的第二个参数< / blah:AC>
< / tem:someParameter2>
< / tem:myservicemethod>
< / soapenv:Body>
< / soapenv:Envelope>

< / cfsavecontent>

现在调用服务。这是我从Ben Nadel的博客中挖掘出来的: http://www.bennadel.com/blog/1809-Making-SOAP-Web-Service-Requests-With-ColdFusion-And-CFHTTP.htm

 < cfhttp 
url =http:/SomeService/Service.svc
method =post
result =httpResponse >
<!---
提示:查看您的WSDL以确定SOAPAction值
--->
< cfhttpparam
type =header
name =SOAPAction
value =http://tempuri.org/SomeService/myservicemethod
/> ;
< cfhttpparam
type =header
name =accept-encoding
value =no-compression
/>
< cfhttpparam
type =xml
value =#trim(soapBody)#
/>
< / cfhttp>


< cfdump var =#httpResponse#/>


I cant find any good samples for that scenario.

Also, the WCF service used the Entity Framework 6.0 which should return big JSON structures. For now I am just trying to find a simple example which can call a simple WCF service:

[ServiceContract]
public interface ITest
{
    [OperationContract(Name = "Test_GetDate")]
    [WebGet(UriTemplate = "/GetDate", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    string GetDate();
...

        public class Test : ITest
        {
            public string GetDate()
            {
                return (DateTime.UtcNow.ToString());
            }
    ...

Thank you

解决方案

Yes it can. This scenario worked for me, but I was using XML format (WCF SOAP) not rest/json, but You can try.

-I use soap UI to figure out how soap Envelope should look like. This tool is free http://www.soapui.org/ and it is easy to use.

-Create New Soap UI project and paste WSDL address in the input, application will generate empty XML request - soap envelope.

-You can test your service from this app

-I am using cfhttp to invoke service from cf:

We figured out soap envelope and we put this in cf variable :

    <cfsavecontent variable="soapBody">

        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:ozon="http://schemas.datacontract.org/blah/prc">
           <soapenv:Header/>
           <soapenv:Body>
              <tem:myservicemethod>
                 <tem:someParameter1>This is my first param</tem:someParameter1>
                 <tem:someParameter2>
                    <blah:AC>This is my second parameter</blah:AC>
                 </tem:someParameter2>
              </tem:myservicemethod>
           </soapenv:Body>
        </soapenv:Envelope>                         

    </cfsavecontent>    

Now invoke service. This I digged from Ben Nadel's blog : http://www.bennadel.com/blog/1809-Making-SOAP-Web-Service-Requests-With-ColdFusion-And-CFHTTP.htm

    <cfhttp
         url="http:/SomeService/Service.svc"
         method="post"
         result="httpResponse">
             <!---
             TIP : Look into your WSDL to figure out SOAPAction value
             --->                        
        <cfhttpparam
             type="header"
             name="SOAPAction"
             value="http://tempuri.org/SomeService/myservicemethod"
             /> 
        <cfhttpparam
             type="header"
             name="accept-encoding"
             value="no-compression"
             />          
        <cfhttpparam
             type="xml"
             value="#trim( soapBody )#"
             />
    </cfhttp>   


<cfdump var="#httpResponse#" />

这篇关于有人能告诉我,如果Colfusion 8可以消耗WCF服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆