问题
I've been running into some challenges with a web service I'm trying to use of from ColdFusion. The service (AccountsService), has a method, GetAccountLinksByUser that returns accounts associated with a given user. This method accepts two arguments:
UPN, which is just a unique string to identify the user. This is no problem, as far as I can tell.
sourceType. This is ultimately a string, but is defined in the WSDL as simple type with one of three possible values. Here's a relevant sections of XML from the WSDL:
<xsd:simpleType name="SourceType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="All"/>
<xsd:enumeration value="Manual"/>
<xsd:enumeration value="System"/>
</xsd:restriction>
</xsd:simpleType>
The problem is that I can't seem to just pass the string "All", "Manual", or "System" into the web service. The stub that CF generates has the following signature for this method:
getAccountLinksByUser(java.lang.String, org.datacontract.schemas._2004._07.tfonline_services_accounts_datacontracts.SourceType)
This appears to suggest that I need to pass in an instance of org.datacontract.schemas._2004._07.tfonline_services_accounts_datacontracts.SourceType. However, I can't create an instance of that type (easily) as it doesn't appear to be in a class path that CF searches. I tried wrapping the classes that CF generates into the /stubs directory into a jar and putting them in a class path. This did work, in that I could now create an instance of org.datacontract.schemas._2004._07.tfonline_services_accounts_datacontracts.SourceType, but I was still unable to pass that into the getAccountLinksByUser method.
As requested, here is the code I'm using to call the web service:
<cfset accountsService = CreateObject("WebService", "http://local.hostname/libraries/com/foo/bar/staging/AccountsService.wsdl") />
<cfset SourceType = CreateObject("java", "org.datacontract.schemas._2004._07.tfonline_services_accounts_datacontracts.SourceType") />
<cfset accounts = accountsService.getAccountLinksByUser("username@domain", SourceType.All) />
More information. The publisher of the web service does not publish their WSDL publicly. This was emailed to me and I'm loading the WSDL from my my local development site.
The specific error I'm getting is:
Cannot perform web service invocation getAccountLinksByUser. The fault returned when invoking the web service operation is:
Cannot perform web service invocation getAccountLinksByUser. The fault returned when invoking the web service operation is: '' java.lang.IllegalArgumentException: argument type mismatch
I'm not really sure where to head at this point. Any suggestions?
The service is written in .NET.
回答1:
I ran a few tests and it seems related to the switch to Axis2 in CF10. I am honestly not sure exactly what about enumeration's changed between 1 and 2. However, setting the version level back to Axis1 should do the trick:
<cfscript>
args = { refreshWSDL=true, wsversion=1 };
ws = createObject("webservice", "http://mysite/test.asmx?wsdl", args);
result = ws.getAccountLinksByUser("test@somewhere.com", "All");
writeDump(result);
</cfscript>
来源:https://stackoverflow.com/questions/15385642/issue-using-net-web-service-from-coldfusion