Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.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
在sharepoint中设置流式WCF服务_Wcf_Sharepoint - Fatal编程技术网

在sharepoint中设置流式WCF服务

在sharepoint中设置流式WCF服务,wcf,sharepoint,Wcf,Sharepoint,我正在尝试在sharepoint中设置一个简单的WCF服务,它将接收流并返回蒸汽。它有一个如下所示的方法: public System.IO.Stream Convert(System.IO.Stream input) { // do stuff here } <binding name="testBinding" maxBufferPoolSize="214748347" maxBufferSize="214748347" maxReceivedMes

我正在尝试在sharepoint中设置一个简单的WCF服务,它将接收流并返回蒸汽。它有一个如下所示的方法:

public System.IO.Stream Convert(System.IO.Stream input)
{
   // do stuff here
}
<binding name="testBinding" maxBufferPoolSize="214748347" maxBufferSize="214748347" 
             maxReceivedMessageSize="214748347"
             transferMode="Streamed">
        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...");
                }
            }
        }
        <basicHttpBinding>
            <binding name="BasicHttpBinding_iSPTest" transferMode="Streamed">
                <security mode="TransportCredentialOnly">
                    <transport clientCredentialType="Ntlm" />
                  <message clientCredentialType="UserName" algorithmSuite="Default"/>
                </security>
            </binding>
        </basicHttpBinding>
起初,我可以让它工作,因为它抱怨请求的大小。我发现这是因为没有在服务器端设置蒸汽。因此,在
web.config
中,我将其绑定设置为:

public System.IO.Stream Convert(System.IO.Stream input)
{
   // do stuff here
}
<binding name="testBinding" maxBufferPoolSize="214748347" maxBufferSize="214748347" 
             maxReceivedMessageSize="214748347"
             transferMode="Streamed">
        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...");
                }
            }
        }
        <basicHttpBinding>
            <binding name="BasicHttpBinding_iSPTest" transferMode="Streamed">
                <security mode="TransportCredentialOnly">
                    <transport clientCredentialType="Ntlm" />
                  <message clientCredentialType="UserName" algorithmSuite="Default"/>
                </security>
            </binding>
        </basicHttpBinding>
但问题是
read
始终为0。尽管我可以确认steam在服务器端有数据,但似乎从来没有字节可读取。因此,我突然想到,问题是我也需要在客户端获取
transferMode
。所以我这样设置:

public System.IO.Stream Convert(System.IO.Stream input)
{
   // do stuff here
}
<binding name="testBinding" maxBufferPoolSize="214748347" maxBufferSize="214748347" 
             maxReceivedMessageSize="214748347"
             transferMode="Streamed">
        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...");
                }
            }
        }
        <basicHttpBinding>
            <binding name="BasicHttpBinding_iSPTest" transferMode="Streamed">
                <security mode="TransportCredentialOnly">
                    <transport clientCredentialType="Ntlm" />
                  <message clientCredentialType="UserName" algorithmSuite="Default"/>
                </security>
            </binding>
        </basicHttpBinding>
这似乎很简单,只是我不知道如何让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'.

这是怎么回事?如何使返回的流可读?是否需要将服务器设置为允许匿名访问?如果是,如何回答?

我间接回答你的问题,作为对一个稍微不同的问题的补充:

我的回答并不是专门针对sharepoint,但它适用于您的情况。本质上,要点是整个质询/响应401交换与流不兼容,因为流可能被发送两次(并且在第一次尝试时被401拒绝)。诀窍是在第一个请求中发送身份验证。这是通过自定义客户端行为/检查器组合完成的,并在客户端WCF配置中禁用身份验证,但在服务器上保持启用状态。在服务器端禁用单个WCF服务的身份验证将导致比在sharepoint环境中更麻烦的问题。相信我:)


祝你好运。

谢谢你的链接。这一个需要我一段时间来消化。目前,我们实际上只是出于一个目的使用Sharepoint。它不是我们通常使用的东西(因此我们对它不熟悉)。当然,如果我们决定以后将其用于其他用途,这种情况可能会改变,因此我不想留下将来的麻烦。好的:我实现了链接答案中的内容,在服务器端不做任何更改,并将客户端设置为使用自定义行为,但是现在我得到一个参数异常,消息是
提供的URI方案“http”无效;应为“https”。
我将
端点
地址(在客户端)更改为
https://myserver...
来自
http
,但随后我得到一个“无端点侦听”https://....". 我将服务器上的
安全
模式从
更改为
传输
,但仍然没有骰子。所以服务器上没有启用SSL?好的,所以不要使用运输安全。服务器和客户端上的url协议应为“none”,url协议应为“http”,并带有
security mode=“none”
,当我使用
启动http请求时,客户端身份验证方案“Anonymous”未经授权。从服务器接收的身份验证标头为“NTLM”。