我成功地为我的 WCF 服务创建了一个服务名字对象作为客户端。但我无法在绰号上调用任何方法。
在 WCF 服务端,我有一个名为 TestMethod 的虚拟方法,如下所示:
Public Function TestMethod(ByVal TestValue As String) As String Implements ICustomerService.TestMethod
Return "You said.... " & TestValue
End Function
以下代码在 Excel 中创建 Moniker。
Public Sub WCFMexMonkierDemo()
' Create a string for the service moniker including the content of the WSDL contract file
Dim mexMonikerString As String
mexMonikerString = "service:mexAddress='http://localhost/CustomerService.svc/mex'" & _
", address='http://localhost/CustomerService.svc'" & _
", binding=CustomerServices.CustomerService" & _
", bindingNamespace='http://tempuri.org/'" & _
", contract=ICustomerService" & _
", contractNamespace='http://tempuri.org/'"
' Create the service moniker object
Dim mexMoniker, result
Set mexMoniker = GetObject(mexMonikerString)
result = mexMoniker.TestMethod("client call") '<-- error on this line
'Set result = mexMoniker.TestMethod("client call")
MsgBox result
Set mexMoniker = Nothing
Set result = Nothing
End Sub
上面的代码在GetObject
调用之前有效,这意味着名字对象已成功创建。但是,一旦我尝试调用任何方法,我就会收到错误消息。
WCF 方法与 Microsoft WCF 测试客户端和其他 WCF 客户端完美配合。所以我知道服务本身没有问题。