【问题标题】:Can someone tell me if Colfusion 8 can consume a WCF service?有人能告诉我 Colfusion 8 是否可以使用 WCF 服务吗?
【发布时间】:2013-09-20 19:10:10
【问题描述】:

我找不到该场景的任何好的样本。

此外,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());
            }
    ...

谢谢

【问题讨论】:

标签: wcf coldfusion


【解决方案1】:

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

-我使用soap UI 来确定soap 信封应该是什么样子。这个工具是免费的http://www.soapui.org/,而且很容易使用。

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

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

-我正在使用 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>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>    

现在调用服务。这是我从 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">
             <!---
             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#" />

【讨论】:

  • 您是说我需要为我调用的每个服务或方法构建一个 SOAP 信封吗?另外,我不希望返回 XML,WCF 设置为返回 JSON.... 有人帮忙,因为我找不到任何关于这个主题的好文章/博客。 -- 谢谢
  • 否 你不需要,因为服务将无法解析它。你的 web 请求定义你正在发送 JSON,因此请求的内容只能是 JSON。我会尝试使用soap ui 或一些类似的工具来测试Web 服务(stackoverflow.com/questions/620333/…) 以确定我需要在正文中发送什么,然后我会使用这种cfhttp 方法。
猜你喜欢
  • 2015-07-30
  • 2020-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-09
  • 2021-11-16
  • 2012-09-16
  • 1970-01-01
相关资源
最近更新 更多