我有一个WCF服务端点。该服务被配置为WCF服务,其中Security = TransportWithMessageCredential,Message被设置为用户名,使用CustomValidator进行用户名/密码验证。
我在c#控制台应用程序中有这段代码(它可以工作):
ServiceClient client = new ServiceClient();
client.ClientCredentials.UserName.UserName = "myusername";
client.ClientCredentials.UserName.Password = "mypassword";
Console.WriteLine(client.GetVersion());上面的代码有效--使用cfinvoke的ColdFusion等效值是什么?我现在有以下内容(在用户名/密码介绍之前,它运行得很好)
<cfinvoke
webservice="#wsurl#"
method="getVersion"
returnvariable="gcversion"
refreshwsdl="true">
</cfinvoke>包含“客户凭据”的适当位置在哪里?
编辑:该服务似乎使用的是“WS”。我很难找到有关CF2016支持WS-Security的信息。这似乎是一个标准,所以我不知道为什么找到信息是困难的。
如果有人能提供任何资源,我将非常感激。
EDIT2:我正在尝试这样做:‘ ws = CreateObject("webservice",wsurl,{refreshwsdl=true});
objSoapHeader = XmlParse("<wsse:Security mustUnderstand=""false"" xmlns:wsse=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd""><wsse:UsernameToken><wsse:Username>myun</wsse:Username><wsse:Password>mypass</wsse:Password></wsse:UsernameToken></wsse:Security>");
addSOAPRequestHeader(ws, "ignoredNameSpace", "ignoredName", objSoapHeader,false);
version =ws.getVersion();
writeOutput(version);
但正在收到以下错误:
Cannot perform web service invocation getVersion.
The fault returned when invoking the web service operation is:
org.apache.axis2.AxisFault: Must Understand check failed for header http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd : Security
at org.apache.axis2.engine.AxisEngine.checkMustUnderstand(AxisEngine.java:105)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:171)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:364)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at cwtgift.CWTGiftServiceStub.getVersion(CWTGiftServiceStub.java:1954)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
The error occurred in C:/ColdFusion2016/cfusion/wwwroot/test/getVersion.cfm: line 19
17 : addSOAPRequestHeader(ws, "ignoredNameSpace", "ignoredName", objSoapHeader,false);
18 :
19 : version =ws.getVersion();
20 : writeOutput(version);
21 : </cfscript>发布于 2017-06-15 18:19:48
由于不知道ServiceClient()的具体情况,我怀疑使用cfinvokeargument可能是传递用户名/密码的最快方法:
<cfinvoke webservice="#wsurl#"
method="getVersion"
returnvariable="gcversion"
refreshwsdl="true">
<cfinvokeargument name="UserName" value="myusername" />
<cfinvokeargument name="Password" value="mypassword" />
</cfinvoke>如果您需要访问未配置为web服务的端点,也可以以类似的方式使用CFHTTP (这里我还没有详细说明所有参数或值,有关详细信息,请参考https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-g-h/cfhttp.html ):
<cfhttp url="" method="" throwOnError="" multipart="" path="" file="" name="" result="">
<cfhttpparam type="" name="UserName" value="myusername" />
<cfhttpparam type="" name="Password" value="mypassword" />
</cfhttp>https://stackoverflow.com/questions/44573358
复制相似问题