【发布时间】:2014-09-24 22:19:49
【问题描述】:
我正在尝试使用简单的控制台应用程序从 Web 服务获取一些数据,但是我收到此错误:
SoapException 未处理
错误 - 缺少标头信息。
我已经尝试过以下文章:
- http://www.codeproject.com/Questions/709641/ERROR-SOAP-Header-Missing
- http://msdn.microsoft.com/en-us/library/y4t36w86(v=vs.80).aspx
但是我不能在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=未知错误 Lang=""
节点=未知错误角色=“”堆栈跟踪: em System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage 消息、WebResponse 响应、流 responseStream、布尔值 异步调用) em System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(字符串 方法名,对象 [] 参数) 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 程序集,String[] args) em System.AppDomain.ExecuteAssembly(字符串 assemblyFile,证据 assemblySecurity,字符串 [] args) em Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() em System.Threading.ThreadHelper.ThreadStart_Context(对象状态) em System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext、ContextCallback 回调、对象状态、布尔值 保留SyncCtx) em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean 保留SyncCtx) em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 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>
我认为问题与身份验证有关,因为我没有在控制台应用程序中设置任何凭据。
【问题讨论】: