gpt4 book ai didi

c# - 从 Coldfusion 调用 C# WebService,我无法获得结果

转载 作者:行者123 更新时间:2023-11-30 17:44:30 25 4
gpt4 key购买 nike

我有一个调用自承载 WCF C# WebService 的 ColdFusion (9) 函数。我将它发布到我的虚拟服务器,并从 SoapUI 调用它并且它工作。

当我使用 CFInvoke 从 ColdFusion 调用它时,我得到一个带有方法列表的红色框。

<cfinvoke 
webservice="http://dev-wcf/sideswebservice/SidesSelfHost.SidesWebService.svc?Wsdl"
method = "GetEmailsFor"
returnVariable = "httpResponse"
>
</cfinvoke>
<cfdump var="#httpResponse#">

CFDump of CFInvoke result

当我使用 CFHTTP 从 ColdFusion 调用它时,我得到带有结构名称的 xml,但没有数据。

<cfhttp 
url="http://dev-wcf/sideswebservice/SidesSelfHost.SidesWebService.svc?Wsdl"
resolveurl="yes"
method="GET"
throwOnError="yes"
>
</cfhttp>
<cfdump var="#cfhttp#">

CFDump of CFHTTP Result

我不禁想到,我在 CF 中收到响应的方式可能与未获取我的电子邮件记录数据有关,因为它在 Soap UI 中有效。

更新 1:

啊,我看到隧道尽头有光了。但是,当我尝试转储 getEaaempBin() 时,它会崩溃并烧毁。

<cfset httpResponse = structNew()> 
<cfinvoke
webservice="dev-wcf/sideswebservice/…";
method="GetEmailsFor"
returnVariable = "httpResponse">
</cfinvoke>
<cfset getEmailRecord = structNew()>
<cfset getEmailRecord = httpResponse.getEmailRecord()>
<cfdump var="#getEmailRecord#">
<cfset getEaaempBin = structNew()>
<!--- <cfset getEaaempBin = getEmailRecord.getEaaempBin()>
<cfdump var="#getEaaempBin#">
-->

CFDump of getEmailRecord() Result

更新 2:这是我最新的 ColdFusion 代码。地址是重复的,而不是真实数据,即 2 条记录。

<cfinvoke webservice="#wsdurl#" 
method="GetEmailsFor"
returnVariable = "httpResponse">
<cfinvokeargument name="bin" value="0000210883"/>
<cfinvokeargument name="population" value="0"/>
</cfinvoke>

<cfset getEmailRecord = httpResponse.getEmailRecord()>
<cfdump var="#getEmailRecord[1].getEmailAddress()#"><br>
<cfdump var="#getEmailRecord[2].getEmailAddress()#">

结果:

charlotte.d.williams@example.com
charlotte.d.williams@example.com

更新 3:

原来重复是由 C# 代码引起的。我做错的唯一一件事(9 个月没有做列表和数据表)是在循环顶部实例化一条新记录……我在循环内为记录添加了一个实例化,现在效果很好。

public List<EmailRecord> GetEmailsFor(string bin, Int32 population){
EmailRecord emailRecord = new EmailRecord();
List<EmailRecord> listEmailRecords = new List<EmailRecord>();
DataTable dt = new DataTable();

//... populate DataTable

foreach (DataRow row in dt.Rows){
if (row["EAAEMP_BIN"] == DBNull.Value){
emailRecord.EaaempBin = "";
}
else{
emailRecord.EaaempBin = (string)row["EAAEMP_BIN"];
}
if (row["EMAIL_ADDRESS"] == DBNull.Value){
emailRecord.EmailAddress = "";
}
else{
emailRecord.EmailAddress = (string)row["EMAIL_ADDRESS"];
}

listEmailRecords.Add(emailRecord);
}

return listEmailRecords;
}

最佳答案

cfinvoke 的结果看起来不错。 Web 服务只是返回某种类型的 wrapped array .尝试转储 httpResponse.getEmailRecord()。它应该包含一组 EmailRecord 对象。

Add results of adding getEmailRecord ... Just get a list of more methods.

更新:

这是应该发生的事情。结果是代表电子邮件记录的 java 对象数组。您需要遍历该数组并在每个对象上调用适当的方法来检索值。方法名称应遵循 bean 模式。即获取SomePropertyName()。最后一张图片有点模糊,所以方法名称可能不对,但你明白了..

 for ( record in httpResponse.getEmailRecord() )
{
// call one of the methods to retrieve
// the value for the given property
writeDump( record.getVerificationText() );
}

When I call it from ColdFusion using CFHTTP, I get xml with structure names, but no data

旁注,原因是您的 cfhttp 调用仅检索定义文件,即 WSDL。它不调用返回数据的方法。

关于c# - 从 Coldfusion 调用 C# WebService,我无法获得结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29657483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com