2017-06-15 41 views
2

我有一個WCF服務端點。該服務被配置爲具有安全模式= TransportWithMessageCredential的WCF服務,並且使用CustomValidator將用戶名/密碼驗證設置爲用戶名的消息安全性clientCredentialType。ColdFusion cfinvoke(消息安全 - ClientCredentials =用戶名)

我有一個C#控制檯應用程序(其中工程)驗證碼:

ServiceClient client = new ServiceClient(); 
    client.ClientCredentials.UserName.UserName = "myusername"; 
    client.ClientCredentials.UserName.Password = "mypassword"; 
    Console.WriteLine(client.GetVersion()); 

上面的代碼工作 - 什麼是ColdFusion的等效利用CFINVOKE? 我現在有(其中工作過的用戶名/密碼引進沒關係)以下

<cfinvoke 
webservice="#wsurl#" 
method="getVersion" 
returnvariable="gcversion" 
refreshwsdl="true"> 
</cfinvoke> 

哪裏是合適的地方,包括「客戶端憑證」?

編輯:看起來該服務正在使用'WS-Security'。我正在努力尋找關於CF2016對WS-Security支持的信息。看起來這是一個標準,所以我不確定爲什麼發現信息很困難。

如果有人可以提供任何資源,我會很感激。

EDIT2: 我試圖做到這一點: ``` WS =的CreateObject( 「Web服務」,wsurl,{refreshwsdl =真});

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> 

回答

2

不知道你的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> 
+0

增加附加問題的細節 –

+0

它是基本身份驗證嗎?如果是這樣,請嘗試使用用戶名和密碼屬性。 – Leigh

+0

Hi @Leigh,我不相信這是基本認證。這是WSS認證。在肥皂UI中,我需要將WSS密碼類型設置爲「文本」,然後在基本下使用用戶名和密碼。 我試圖使用用戶名和密碼屬性,以及設置authType BASIC –