0

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

Max
  • 1,289
  • 3
  • 26
  • 50
  • 1
    Have you tried using `cfinvoke` or `createbject()` to hit the WSDL? Here is some info - http://paulhelyer.com/blog/?p=5 – Scott Stroz Sep 20 '13 at 19:21
  • Here is an example: http://stackoverflow.com/questions/14146897/consuming-a-wcf-webservice-with-arrayofint-paramenter – James A Mohler Sep 20 '13 at 19:58
  • I get the error below (I can browse the service fine via IP below): java.util.NoSuchElementException: null The error occurred in D:\WebSites\Coldfusion\test\Test.cfm: line 7 5 : webservice="http://xxx.xxx.xxx.xxx/Company.Web/svc/Test.svc?wsdl" 6 : method="GetDate" 7 : returnvariable="response" 8 : > 9 : – Max Sep 20 '13 at 21:09
  • Sounds like you are missing a required parameter – James A Mohler Sep 20 '13 at 21:10

1 Answers1

1

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#" />
nkostic
  • 565
  • 2
  • 7
  • 19
  • are you saying I need to build a SOAP envelope for each service or method I call? Also, I don't want XML back, the WCF is set to return JSON.... someone help because I cant find any good articles/blogs about this topic. -- thanks – Max Sep 26 '13 at 20:40
  • No You don't need, because service will not be able to parse it.Your web request defines that you are sending JSON, therefore the content of the request can be only JSON. I would try with soap ui or some similar tool for testing web services(http://stackoverflow.com/questions/620333/whats-the-best-way-to-test-wcf-services) to figure out what I need to send in the body and then I would use this cfhttp approach. – nkostic Sep 26 '13 at 21:25