我正在尝试使用简单的控制台应用程序从Web服务获取一些数据,但是我收到此错误:
SoapException未得到处理 错误 - 缺少标题信息。
我已经尝试过以下文章:
但我不允许在WebServer端工作,因此我无能为力。
代码:
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
myWS.WServer WebService = new myWS.WServer();
string[] myMethods = WebService.GetMethods();
}
}
}
按照完整的错误消息:
System.Web.Services.Protocols.SoapException未处理
HResult = -2146233087消息=错误 - 缺少标题信息。
Source = System.Web.Services Actor = Unknown Error Lang =""
节点=未知错误角色=""堆栈跟踪: em System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage) 消息,WebResponse响应,流responseStream,布尔值 asyncCall) em System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName,Object []参数) em ConsoleApplication3.myWS.WServer.GetMethods()na c:\ VS \ ConsoleApplication3 \ ConsoleApplication3 \ Web 参考文献\ myWS \ Reference.cs:linha 532 em ConsoleApplication3.Program.Main(String [] args)na c:\ VS \ ConsoleApplication3 \ ConsoleApplication3 \ Program.cs:linha 14 em System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,String [] args) em System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args) em Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() em System.Threading.ThreadHelper.ThreadStart_Context(Object state) em System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback回调,对象状态,布尔值 preserveSyncCtx) em System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态,布尔值 preserveSyncCtx) em System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态) em System.Threading.ThreadHelper.ThreadStart()InnerException:
尽管存在以上问题,但使用SoapUI
和XML
,它确实有效。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ver="http://www.multispeak.org/Version_3.0">
<soapenv:Header>
<ver:MultiSpeakMsgHeader Version="3.0" UserID="myId" Pwd="myPwd" AppName="?" AppVersion="?" Company="?" CSUnits="feet" CoordinateSystem="?" Datum="?" SessionID="?" PreviousSessionID="?" ObjectsRemaining="?" LastSent="?" RegistrationID="?"/>
</soapenv:Header>
<soapenv:Body>
<ver:GetMethods/>
</soapenv:Body>
我认为问题与身份验证有关,因为我没有在控制台应用程序中设置任何凭据。
答案 0 :(得分:0)
我想出了如何解决它 它与身份验证有关,如下例所示:
WebService .MultiSpeakMsgHeaderValue = new MultiSpeakMsgHeader {
Pwd = "***",
UserID = "***"
};
在调用方法之前。