Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从bat文件调用WCF服务_Wcf_Batch File - Fatal编程技术网

从bat文件调用WCF服务

从bat文件调用WCF服务,wcf,batch-file,Wcf,Batch File,是否可以在bat文件中调用WCF服务的方法。我们想测试重启服务器后WCF服务是否正常工作。BAT文件范围内没有允许您直接联系WCF服务的命令,但是您可以使用BAT文件运行可以连接WCF服务并与之交互的现有控制台程序。所以答案是肯定和否定的;不是直接的,而是通过一个单独的程序 如果您需要一些简单、可点击的方式来访问WCF服务,我会选择Powershell或VB脚本(假设您在windows环境中)。也许您可以使用Powershell?那就容易多了。创建包含内容的脚本: $url = 'http://

是否可以在bat文件中调用WCF服务的方法。我们想测试重启服务器后WCF服务是否正常工作。

BAT文件范围内没有允许您直接联系WCF服务的命令,但是您可以使用BAT文件运行可以连接WCF服务并与之交互的现有控制台程序。所以答案是肯定和否定的;不是直接的,而是通过一个单独的程序


如果您需要一些简单、可点击的方式来访问WCF服务,我会选择Powershell或VB脚本(假设您在windows环境中)。

也许您可以使用Powershell?那就容易多了。创建包含内容的脚本:

$url = 'http://yoursite.url/example.svc'
$action = "`"http://some.namespace/method`""
$SOAPRequest = [xml]@'heregoesxmlmessage'@

write-host "Sending SOAP Request To Server: $url" 
$soapWebRequest = [System.Net.WebRequest]::Create($url) 
$soapWebRequest.Headers.Add("SOAPAction", $action)

$soapWebRequest.ContentType = "text/xml;charset=`"utf-8`"" 
$soapWebRequest.Accept      = "text/xml" 
$soapWebRequest.Method      = "POST" 

write-host "Initiating Send." 
$requestStream = $soapWebRequest.GetRequestStream() 
$SOAPRequest.Save($requestStream) 
$requestStream.Close() 

write-host "Send Complete, Waiting For Response." 
$resp = $soapWebRequest.GetResponse() 
$responseStream = $resp.GetResponseStream() 
$soapReader = [System.IO.StreamReader]($responseStream) 
$ReturnXml = [Xml] $soapReader.ReadToEnd() 
$responseStream.Close() 

write-host "Response Received."
$ReturnXml.OuterXml | out-file ".\test.xml"
write-host $ReturnXml.OuterXml

如其他答案中所述,Powershell可能是使用
New WebServiceProxy
cmdlet的最佳方式

上面链接中的示例:

PS C:\> $URI = "http://www.webservicex.net/uszip.asmx?WSDL"
PS C:\>$zip = New-WebServiceProxy -Uri $URI -Namespace WebServiceProxy -Class USZip
PS C:\> $zip.getinfobyzip(20500).table
CITY      : Washington
STATE     : DC
ZIP       : 20500
AREA_CODE : 202
TIME_ZONE : E