使用参数从 VBScript、WScript、VBA 等调用 WCF (.svc) 服务 [英] Call WCF (.svc) service from VBScript, WScript, VBA, etc with parameters

查看:29
本文介绍了使用参数从 VBScript、WScript、VBA 等调用 WCF (.svc) 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试实现下面之前发布的问题中提供的示例:

I've been trying to implement the exmaples provided in the question posted previously below:

通过 VBScript 调用 WCF 服务

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

In my specific scenario I need to pass in a single string variable which will return an array of strings but having little luck.

我怀疑我很难正确处理信封请求.下面是我试图调用的 wdsl.你能给我一个例子来说明我如何调用这个传入参数并解析返回数组吗?

I suspect I'm having a tough time getting the envelope request correct. Below is the wdsl that I'm trying to call. Can you give me an example of how i can call this passing in the parameter and parsing the return array?

  <?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>

推荐答案

此 WSDL 文档不包含用于操作,因此仅凭这些信息无法判断请求应该是什么样子.

This WSDL document doesn't contain the schema (all the <wsdl:import> statements) for the input / output of the operations, so it's impossible to tell what the request should look like based on this information alone.

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

But one thing you can do: open WCFTestClient.exe, point it to the WSDL of the running service, then - while running a tool such as Fiddler - send a request to the service. This way you'll be able to see the request going on, and the service response. At that point, replicate the request (including things such as the HTTP header SOAPAction, if applicable), and the request body.

这篇关于使用参数从 VBScript、WScript、VBA 等调用 WCF (.svc) 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆