我目前正在探索powershell功能,但我遇到了一个我无法解决的问题.任何快速提示将不胜感激=)
我的目标:从powershell v2.0调用WCF服务(使用MTOM消息编码配置)中的方法(希望使用new-webserviceproxy cmdlet)
我的问题:当消息编码设置为Mtom时,new-webserviceproxy cmdlet无法正确解析服务的响应.我收到以下错误:
PowerShell:
$proxyObject = New-WebServiceProxy -URI "http://myserver.com/AccessService.svc?wsdl"
$proxyObject.TestWebServiceConnection()
使用"0"参数调用"TestWebServiceConnection"的异常:"客户端发现响应内容类型为'multipart/related; type ="application/xop + xml"; start ="<http://tempuri.org/0> "; boundary ="uuid:
4001d529-32b9-4560-9f4b-550c35c67b03 + id = 4"; start-info ="text/xml"',但预期'text/xml'.
请求失败并显示错误消息:
- -
--uuid:4001d529-32b9-4560-9f4b-550c35c67b03 + ID = 4
的Content-ID:<http://tempuri.org/0>
内容传送编码:8位
内容类型:应用/ XOP + xml的; charset = utf-8; type ="text/xml"
<s:Envelope xmlns:s ="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<TestWebServiceConnectionResponse xmlns ="http: //myserver.com /">
<TestWebServiceConnectionResult>成功</ TestWebServiceConnectionResult>
</ TestWebServiceConnectionResponse>
</ S:身体>
</秒:信封>
--uuid:4001d529-32b9-4560-9f4b-550c35c67b03 + ID = 4- -
- ."
在行:1 char:38
+ $ …
我正在尝试使用 SharpZipLib 生成 zip 文件并让客户端下载它。
当前 zip 文件夹已创建并可在客户端计算机上使用,但问题是 download.zip 文件夹为空。文件夹中指定的文件在 zip 文件夹中不可用。
下面是我尝试过的代码。
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
ICSharpCode.SharpZipLib.Checksums.Crc32 crc = new ICSharpCode.SharpZipLib.Checksums.Crc32();
//stream directly to client.
ICSharpCode.SharpZipLib.Zip.ZipOutputStream output = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(response.OutputStream);
output.SetLevel(9);
string[] files = Directory.GetFiles("D:/newfolder/");
for (int i = 0; i < files.Length; i++)
{
ICSharpCode.SharpZipLib.Zip.ZipEntry entry = new ICSharpCode.SharpZipLib.Zip.ZipEntry(files[i].ToString());
entry.DateTime = DateTime.Now;
System.IO.FileStream fs = new System.IO.FileStream(files[i].ToString(), FileMode.Open);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
entry.Size = fs.Length;
fs.Close();
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
output.PutNextEntry(entry);
output.Write(buffer, 0, …Run Code Online (Sandbox Code Playgroud)