2012-04-13 70 views
0

我有一個WCF REST服務需要與另一個WCF REST服務進行通信。WCF到WCF通信401,HttpClient

有三家網站:

  • 默認Web站點
  • WEBSITE1
  • WEBSITE2

如果我成立於默認Web站點兩種服務,並連接到其他(使用HttpClient )使用URI http://localhost/service然後一切都很好。

所需的設置是將這兩個服務移動到單獨的網站,而不是使用URI http://localhost/service,通過http://website1.domain.com/service訪問服務仍然使用HttpClient

我接收到異常:

System.ArgumentOutOfRangeException:未經授權(401)是 以下不之一:行(200),創建日期(201),接受(202), NonAuthoritativeInformation(203 ),NoContent(204),ResetContent (205),PartialContent(206)

我可以看到這是一個401,但是這到底是怎麼回事呢?

謝謝

+1

如果你可以添加你的HttpClient代碼(配置/執行)它會幫助你找出問題最有用的。 – 2012-04-15 18:15:10

回答

0

我認爲這與您的web服務設置有關。最好是創建GET,POST,Put,刪除心跳呼叫以獲取新服務,然後檢查來自提琴手的心跳呼叫。如果您獲得401,這可能意味着您的應用程序池標識無法訪問某些內容。

步驟來解決這個問題:

  1. 給用戶的讀/寫/修改/執行/ ..在你的WCF類似權利發佈文件夾
  2. 創建這個網站在.NET 4中集成
  3. 應用程序池
  4. 設置該用戶對應用程序池標識,啓用匿名模式
  5. 啓用PUT,DELETE動詞以及

部分中heartbea的在服務萬噸級測試呼叫:

[DataContract] 
public class StatusInfo 
{ 
    [DataMember] 
    public string MachineName { get; set; } 

    [DataMember] 
    public string IpAddress{ get; set; } 

    [DataMember] 
    public string Methodname { get; set; } 

    public override string ToString() 
    { 
     return "Machinename:" + MachineName + " ;IP:" + IpAddress + "; Method:" + Methodname; 
    } 
} 

private void ResolveStatus(StatusInfo statusInfo,string methodname) 
    { 
     try 
     { 
      var context = System.ServiceModel.OperationContext.Current; 

      RemoteEndpointMessageProperty property = 
       (RemoteEndpointMessageProperty) 
       context.IncomingMessageProperties[RemoteEndpointMessageProperty.Name]; 


      statusInfo.IpAddress = property.Address; 
      statusInfo.MachineName = Environment.MachineName; 
      statusInfo.Methodname = methodname; 

     }catch(Exception ex) 
     { 

     } 
    } 
/// <summary> 
    /// create task 
    /// </summary> 
    /// <param name="taskwrapped"></param> 
    [WebInvoke(Method = "POST", UriTemplate = "", RequestFormat = WebMessageFormat.Json, 
     ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)] 
    public StatusInfo postcall() 
    { 
     StatusInfo statusInfo = new StatusInfo(); 
     logger.Trace(Tagname + "postcall"); 
     ResolveStatus(statusInfo, "POST"); 
     return statusInfo; 

    } 


    /// <summary> 
    /// edit task 
    /// </summary> 
    [WebInvoke(Method = "PUT", UriTemplate = "", RequestFormat = WebMessageFormat.Json, 
       ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)] 
    public StatusInfo Edit() 
    { 
     StatusInfo statusInfo = new StatusInfo(); 
     logger.Trace(Tagname + "Edit"); 
     ResolveStatus(statusInfo, "PUT"); 
     return statusInfo; 

    } 

    //delete request with taskid 
    [WebInvoke(Method = "DELETE", UriTemplate = "", RequestFormat = WebMessageFormat.Json, 
    ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)] 
    public StatusInfo DeleteCall() 
    { 
     StatusInfo statusInfo = new StatusInfo(); 
     logger.Trace(Tagname + "Edit"); 
     ResolveStatus(statusInfo, "DELETE"); 
     return statusInfo; 

    } 


    //delete request with taskid 
    [WebInvoke(Method = "DELETE", UriTemplate = "/{recordid}", RequestFormat = WebMessageFormat.Json, 
    ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)] 
    public StatusInfo DeleteCallWithParam(string recordid) 

    { 
     StatusInfo statusInfo = new StatusInfo(); 
     logger.Trace(Tagname + "Edit"); 
     ResolveStatus(statusInfo, "DELETE/"+recordid); 
     return statusInfo; 

    } 



enter code here 
0

我接收到異常:

誰是 「我」?其中一個Web服務或其他客戶端?

如果我理解正確的事情,那就是似乎在期待一系列的反應,401 就是其中一個接收端。它可能有一些錯誤檢查代碼需要「這個範圍」的響應,並且X(並且401不是其中之一,或者沒有「默認」方法來解釋x響應?)。

也就是說,401是一個授權錯誤,以便檢查可能ServiceAuthorizationManager和/或沒有被「我」導致擺在首位的401響應滿足制定類似的設置....

Hth ...