我遇到了将流类型变量传递给自托管的休息服务的问题。
这是我在客户端应用程序中的代码
static void Main(string[] args)
{
ChannelFactory<IService> cf = new ChannelFactory<IService>(new WebHttpBinding(), "http://localhost:8000");
cf.Endpoint.Behaviors.Add(new WebHttpBehavior());
IService channel = cf.CreateChannel();
string strQuery = "<?xml version=\"1.0\"?><wql host='192.168.1.115' username='domain\\sebastian' password='password' Type='powershell'><query id='0.' ns='root\\cimv2' devicetype='powershell'><![CDATA[select CSName from Win32_OperatingSystem]]></query></wql>";
byte[] byteArray = Encoding.UTF8.GetBytes(strQuery);
MemoryStream stream = new MemoryStream(byteArray);
XmlDocument ResultSet = new XmlDocument();
ResultSet = channel.postGeneralXMLDocument(stream);
Console.Read();
}
这最终会在自托管服务中调用方法“postGeneralXMLDocument”。
此处“Stream strInput”未包含预期内容。
[XmlSerializerFormat]
public XmlDocument postGeneralXMLDocument(Stream strInput)
{
try
{
StreamReader sr = new StreamReader(strInput);
String strRequest = sr.ReadToEnd();
sr.Dispose();
NameValueCollection qs = HttpUtility.ParseQueryString(strRequest);
strQuery = qs["strQuery"];
//Do something
}
catch (Exception Ex)
{
}
}
接口就是这样..
[ServiceContract]
public interface IService
{
[XmlSerializerFormat]
[OperationContract]
[WebInvoke]
XmlDocument postGeneralXMLDocument(Stream strInput);
}
}
我指的是以下网址来构建此
如果有人可以帮助我解决这个问题,那就太棒了
谢谢&amp;问候 塞巴斯蒂安
答案 0 :(得分:1)
可能你没有正确配置wcf。 WCF有4种类型的传输,默认的不是流媒体友好型。
请查看上面的链接以获取更多信息。您应该能够在阅读后使您的项目正常工作。
http://net-daylight.blogspot.com/2011/12/streaming-in-wcf.html http://bartwullems.blogspot.com/2011/01/streaming-files-over-wcf.html