【发布时间】:2014-06-03 12:55:33
【问题描述】:
我在将流类型变量传递给自托管休息服务时遇到问题。
这是我在客户端应用程序中的代码
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);
}
}
我指的是以下 URL 来构建它
如果有人能帮我解决这个问题,那就太好了
感谢和问候 塞巴斯蒂安
【问题讨论】:
-
什么意思>"Stream strInput" 没有携带预期的内容。
-
顺便说一句,您的主要方法中有很多不好的做法,请在此处查看 => msdn.microsoft.com/en-us//library/yh598w02.aspx
-
问题出在我的代码本身。我已经解决了。对造成的不便表示歉意。感谢您提供信息。
标签: c# wcf self-hosting