2014-09-24 80 views
0

我試圖從Web服務得到一些數據,使用一個簡單的控制檯應用程序,但是我得到這個錯誤:的SoapException - 缺少的頭信息

SoapException was unhandled
Error - Missing Header Information.

我已經嘗試下面的文章:

但我我不允許在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 was unhandled
HResult=-2146233087 Message=Error - Missing Header Information.
Source=System.Web.Services Actor=Unknown Error Lang=""
Node=Unknown Error Role="" StackTrace: em System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) em System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) em ConsoleApplication3.myWS.WServer.GetMethods() na c:\VS\ConsoleApplication3\ConsoleApplication3\Web References\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 callback, Object state, Boolean preserveSyncCtx) em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) em System.Threading.ThreadHelper.ThreadStart() InnerException:

儘管有上述的問題,用SoapUIXML,它確實效果很好。

<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

我想出瞭如何解決它。
據相關認證,如下面的例子:

WebService .MultiSpeakMsgHeaderValue = new MultiSpeakMsgHeader { 
    Pwd = "***", 
    UserID = "***" 
}; 

調用之前的方法。