【发布时间】:2014-12-11 02:22:52
【问题描述】:
我正在尝试在 sharepoint 中设置一个简单的 WCF 服务,该服务将获取流并返回流。它有一个看起来像这样的方法:
public System.IO.Stream Convert(System.IO.Stream input)
{
// do stuff here
}
起初,我可以让它工作,因为它抱怨请求的大小。我发现这是由于未将其设置为在服务器端进行流式传输。所以在web.config,我这样设置它的绑定:
<binding name="testBinding" maxBufferPoolSize="214748347" maxBufferSize="214748347"
maxReceivedMessageSize="214748347"
transferMode="Streamed">
这似乎解决了第一个问题,我现在可以在我的 Convert 方法中看到一个蒸汽,它似乎正在处理它。现在的问题在于回程。在我的客户端代码中,我做了这样的事情:
using (StreamReader sr = new StreamReader(file))
{
var sout = ts.Convert(sr.BaseStream);
using (var fs = File.Create(file + ".converted"))
{
while ((read = sout.Read(buffer, 0, buffer.Length)) > 0)
{
fs.Write(buffer, 0, read);
Console.WriteLine("Wrote " + read + " bytes...");
}
}
}
但问题是read 始终为 0。即使我可以确认 steam 在服务器端有数据,似乎也没有要读取的字节。所以我想到问题是我也需要在客户端获取transferMode。所以我这样设置:
<basicHttpBinding>
<binding name="BasicHttpBinding_iSPTest" transferMode="Streamed">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" />
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
但是现在,当我尝试在我的服务上使用任何方法(包括常规的、非 Steam 的)时,我得到了这个错误:
HTTP request streaming cannot be used in conjunction with HTTP authentication.
Either disable request streaming or specify anonymous HTTP authentication.
这似乎很简单,但我不知道如何让 Sharepoint 服务器接受匿名连接。如果我删除 security 的东西,或者在服务器端添加 security 部分并使用 mode = none,我会得到 MessageSecurityException:
The HTTP request is unauthorized with client authentication scheme 'Anonymous'.
The authentication header received from the server was 'NTLM'.
那么这里发生了什么?如何让我返回的流可读?我需要将服务器设置为允许匿名访问吗?如果有,怎么做?
【问题讨论】:
标签: wcf sharepoint