2013-08-16 66 views
0

我已經查看了將HTTP頭添加到SOAP請求的答案,並找到了一些好的並使用了代碼。我想我在附加的代碼中擁有一切,但是當我在Fiddler中查看請求時,看不到任何頭文件被添加。有人可以看看我在這裏是否缺少東西嗎?謝謝。這是一項PeopleSoft服務。不能將HTTP頭添加到SOAP請求中

UTZ_EMP_BIO_INFO_PortTypeClient utz = new UTZ_EMP_BIO_INFO_PortTypeClient(); 
UTZ_EMP_BIO_INFO_PortType utShare = utz; 


using (System.ServiceModel.OperationContextScope scope = new System.ServiceModel.OperationContextScope((IContextChannel)utz.InnerChannel)) 
     { 
      MessageHeaders messageHeadersElement = System.ServiceModel.OperationContext.Current.OutgoingMessageHeaders; 
      messageHeadersElement.Add(MessageHeader.CreateHeader("SOAPAction", String.Empty, "UTZ_EMP_BIO_INFO.v1")); 

      Console.WriteLine("down under"); 
      SendEmpBioRespV1 resp = default(SendEmpBioRespV1); 
      rqst.GetEmpBioInfoReq.GetEmpBioInfo.UTZ_EMP_SRCH_VW.SSN = "123456789"; 
      rqst.GetEmpBioInfoReq.GetEmpBioInfo.UTZ_EMP_SRCH_VW.EMPLID = ""; 
      resp = utShare.UTZ_EMP_BIO_INFO(rqst); 
      Console.WriteLine(resp.SendEmpBioResp.SendEmpBioInfo.UTZ_EMP_BIO_WRK.CITY); 
     } 

回答

0

我會建議您使用HttpWebRequest類:

http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx

HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://www.contoso.com/");

然後就可以調用Headers.Add

myReq.Headers.Add("SOAPAction", "\"http://www.contoso.com/Action\"");

UPDATE :一個例子:How to send/receive SOAP request and response using C#?

根據你的例子,我會使用類似:

using (System.ServiceModel.OperationContextScope scope = new System.ServiceModel.OperationContextScope((IContextChannel)utz.InnerChannel)) 
{ 
    MessageHeaders messageHeadersElement = MessageHeader.CreateHeader("SOAPAction", String.Empty, "UTZ_EMP_BIO_INFO.v1"); 

    OperationContext.Current.OutgoingMessageHeaders.Add(messageHeadersElement); 
etc... 

來自 http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontextscope.aspx

+0

什麼是'HttpWebRequest'有什麼關係? –

+0

我想我假設這個問題是關於「添加HTTP頭到SOAP請求」,我會使用'HttpWebRequest'來處理SOAP請求。 http://stackoverflow.com/questions/2434703/using-the-httpwebrequest-class 也許我錯誤地理解了這個問題,如果我這樣做了,我很抱歉。如果它不適合你,請不要選擇/投票。你會推薦約翰嗎? –

+0

@JohnSaunders?爲先前的評論。 –

相關問題