2013-03-22 63 views
0

我一直在研究一種服務,該服務將用於身份驗證以及爲Android客戶端和桌面客戶端發送和接收數據。該服務基於之前創建的模板,用於需要使用SQL成員資格提供程序的身份驗證服務的人員。從C#客戶端訪問WCF服務中的方法時遇到問題

所以這個項目被分成了3個。一個是公共授權類,另一個是WCF服務,第三個是我用C#開始的客戶端。

我的問題是,我無法從我已經添加到服務/接口的客戶端訪問任何新的方法。除了新的,我可以訪問所有其他的。它也不會在intellisense中顯示。我有一個用於引用該項目的Web引用。我不確定爲什麼它是一個Web引用而不是服務引用,除非我很快意識到它不允許由於授權而添加服務引用。它基本上一直在不停地詢問證書。

這裏是服務的一個例子:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.Text; 
using System.Security.Permissions; 
using System.ServiceModel.Activation; 

namespace DevLake.BasicAuth.Service 
{ 
    // AspNetCompatibilityRequirements is needed to capture the HttpContext.Current in establishing authorization 
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] 
    public class BasicAuthService : IBasicAuthService 
    { 
     public string TestServiceOK() 
     { 
      return "Basic Auth Service Working"; 
     } 

     [PrincipalPermission(SecurityAction.Demand, Role = "Role1")] 
     public string TestRoleAccess() 
     { 
      return "Role can access"; 
     } 

     public string TestMyService() 
     { 
      return DateTime.Now.ToString(); 
     } 

     public void TestError() 
     { 
      throw new System.Exception("Test Exception"); 
     } 
    } 
} 

這裏是匹配接口的例子:我使用來調用這些方法的代碼的一個簡單的例子

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.Text; 

namespace DevLake.BasicAuth.Service 
{ 
    [ServiceContract] 
    public interface IBasicAuthService 
    { 
     [OperationContract] 
     string TestServiceOK(); 

     [OperationContract] 
     string TestRoleAccess(); 

     [OperationContract] 
     string TestMyService(); 

     [OperationContract] 
     void TestError(); 

     } 
} 

而且服務:

private void btnTestService_Click(object sender, RoutedEventArgs e) 
     { 

      try 
      { 
       wsBasicAuthService.BasicAuthService c = new wsBasicAuthService.BasicAuthService(); 
       c.Credentials = new NetworkCredential(txtUserName.Text, txtPassword.Password); 
       MessageBox.Show(c.TestServiceOK()); 

      } 
      catch (System.Exception ex) 
      { 
       MessageBox.Show("Error: " + ex.Message); 
      } 
     } 

任何人都可以看到任何可能導致此問題?

回答

0

您是否嘗試過更新您的參考?你應該能夠右鍵點擊參考和更新。如果這不起作用,請將其刪除並重新添加並查看是否有效。

+0

呃哦,好像我有一個新問題。當我嘗試更新引用時,我遇到與嘗試添加服務引用時相同的錯誤。它只是不斷重複詢問用戶名和密碼的對話框。 – user1632018 2013-03-22 01:57:12

+0

好消息是現在我知道我的第一個問題是參考需要更新。非常感謝你的幫忙。 – user1632018 2013-03-22 02:02:11

+0

如果您的服務正在另一臺計算機上運行,​​它應該提示輸入憑據。您應該爲服務所在的計算機輸入憑據。 – 2013-03-22 02:03:18

相關問題