使用参数从VBScript,WScript,VBA等调用WCF(.svc)服务

时间:2012-05-04 19:34:40

标签: wcf web-services vba vbscript wsh

我一直在努力实现以前发布的问题中提供的exmaples:

Calling WCF service by VBScript

在我的特定场景中,我需要传入一个字符串变量,该变量将返回一个字符串数组但运气不佳。

我怀疑我很难获得正确的信封请求。下面是我试图打电话的wdsl。你能举个例子说明我如何在参数中调用这个传递并解析返回数组吗?

  <?xml version="1.0" encoding="utf-8" ?> 
 <wsdl:definitions name="TestSvc" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata">
 <wsdl:types>
 <xsd:schema targetNamespace="http://tempuri.org/Imports">
  <xsd:import schemaLocation="http://localHost/testSvc.svc?xsd=xsd0" namespace="http://tempuri.org/" /> 
  <xsd:import schemaLocation="http://localHost/testSvc.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" /> 
  <xsd:import schemaLocation="http://localHost/testSvc.svc?xsd=xsd2" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" /> 
  </xsd:schema>
  </wsdl:types>
 <wsdl:message name="ITestSvc_GetDataBy_Id_InputMessage">
 <wsdl:part name="parameters" element="tns:GetDataBy_Id" /> 
 </wsdl:message>
 <wsdl:message name="ITestSvc_GetDataBy_Id_OutputMessage">
  <wsdl:part name="parameters" element="tns:GetDataBy_IdResponse" /> 
  </wsdl:message>
 <wsdl:portType name="ITestSvc">
 <wsdl:operation name="GetDataBy_Id">
  <wsdl:input wsaw:Action="http://tempuri.org/ITestSvc/GetDataBy_Id" message="tns:ITestSvc_GetDataBy_Id_InputMessage" /> 
  <wsdl:output wsaw:Action="http://tempuri.org/ITestSvc/GetDataBy_IdResponse" message="tns:ITestSvc_GetDataBy_Id_OutputMessage" /> 
  </wsdl:operation>
 <wsdl:binding name="BasicHttpBinding_TestSvc" type="tns:ITestSvc">
  <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
 <wsdl:operation name="GetDataBy_Id">
  <soap:operation soapAction="http://tempuri.org/ITestSvc/GetDataBy_Id" style="document" /> 
 <wsdl:input>
  <soap:body use="literal" /> 
  </wsdl:input>
 <wsdl:output>
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
 <wsdl:service name="TestSvc">
 <wsdl:port name="BasicHttpBinding_ITestSvc" binding="tns:BasicHttpBinding_ITestSvc">
  <soap:address location="http://localhost/TestSvc.svc" /> 
  </wsdl:port>
  </wsdl:service>
  </wsdl:definitions>

1 个答案:

答案 0 :(得分:1)

此WSDL文档不包含操作输入/输出的模式(所有<wsdl:import>语句),因此仅根据此信息无法确定请求的外观。

但您可以做的一件事:打开WCFTestClient.exe,将其指向正在运行的服务的WSDL,然后 - 运行Fiddler等工具 - 向服务发送请求。这样您就可以看到正在进行的请求以及服务响应。此时,复制请求(包括HTTP标头SOAPAction等内容,如果适用)和请求正文。