问题
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
回答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#" />
来源:https://stackoverflow.com/questions/18924162/can-someone-tell-me-if-colfusion-8-can-consume-a-wcf-service