2014-02-14 74 views
0

我需要能夠爲我創建的Web服務中的每個接口配置一個端點。 使用測試Web窗體應用程序,我可以成功使用任一接口。但是,當我嘗試添加第二個端點與第二接口,我得到的錯誤如下:爲具有多個接口的Web服務配置端點

Error when updating service reference 下面是Web服務的web.config文件:

<basicHttpBinding> 
     <binding name="myBindingConfiguration1" closeTimeout="00:01:00" /> 
    </basicHttpBinding> 
    </bindings> 

    <services> 
     <service behaviorConfiguration="PaymentServiceBehavior" name="PaymentService.PaymentService"> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <endpoint address="" binding="basicHttpBinding" bindingConfiguration="myBindingConfiguration1" 
      name="PaymentInsecureService" contract="PaymentService.IPaymentService" /> 
     <endpoint address="" binding="basicHttpBinding" bindingConfiguration="myBindingConfiguration1" 
      name="PaymentSecureService" contract="PaymentService.IPaymentSecureService" /> 
     </service> 
    </services> 

這是網絡。從測試應用程序配置文件:

<bindings> 
    <basicHttpBinding> 
    <binding name="BasicHttpBinding_IPaymentService" /> 
    </basicHttpBinding> 
</bindings> 
<client> 
    <endpoint address="http://localhost:4567/Payment.svc" binding="basicHttpBinding" 
    bindingConfiguration="BasicHttpBinding_IPaymentService" contract="PaymentService.IPaymentService" 
    name="PaymentInsecureService" /> 
    <endpoint address="http://localhost:4567/Payment.svc" binding="basicHttpBinding" 
    bindingConfiguration="BasicHttpBinding_IPaymentService" contract="PaymentService.IPaymentSecureService" 
    name="PaymentSecureService" /> 
</client> 

這是Web服務接口的代碼:

namespace PaymentService 
{ 
    [ServiceContract (Namespace = "name of namespace here")] 
    public interface IPaymentSecureService 
    { 
     //Initiate a credit card authorization. 
     [OperationContract(IsOneWay = true)] 
     void Authorize(...12 parameters here...); 

     more methods here.... 
    } 
} 

namespace PaymentService 
{ 
    [ServiceContract (Namespace = "name of namespace here")] 
    public interface IPaymentService 
    { 
     //Initiate a credit card authorization. 
     [OperationContract(IsOneWay = true)] 
     void Authorize(...13 parameters here....); 

     more methods here... 
    } 
} 

當其中一個接口方法具有相同名稱但方法簽名不同時,是否可以爲每個接口設置一個端點?

我的配置文件有問題嗎?

謝謝。

+0

您是否嘗試過在元端點上啓用httpGet? – HOKBONG

+0

這是在Web服務文件中。爲了避免公開元數據信息,請將下面的值設置爲false,並在部署前刪除上面的元數據端點 - > > < <! - 爲了調試而接收故障中的異常詳細信息,請將下面的值設置爲true。在部署之前設置爲false以避免公開異常信息 - >

回答

0

我在其他2個論壇發佈了這個問題。雖然你應該能夠有2個接口,用同樣的方法名稱,但不同的簽名,並使用2點的端點訪問每個接口的,我不相信這是不可能的,除非你做下列之一:

  1. 的每個接口的名稱空間都是唯一的。
  2. 重載方法的name屬性是唯一的。

我選擇第一個選項,因爲我正在更新遺留代碼,並且向方法中添加name屬性實質上會更改方法的名稱。因此,在服務中使用此方法的所有客戶端應用程序都需要進行更改。我想盡量減少對這些應用程序的更改,所以我改變了命名空間。

我認爲這個命名空間屬性用來指向服務所在的位置。根據微軟文檔和我有限的本地測試,情況並非如此。這是文檔的摘錄:

使用您控制的名稱空間標識您的XML Web服務。例如,您可以使用公司的Internet域名作爲名稱空間的一部分。許多XML Web服務名稱空間與URL類似,但名稱空間不必指向Web上的實際資源。 (XML Web服務名稱空間是URI。)(統一資源標識符)。通過使用XML名稱空間,您可以在xml文檔中唯一標識元素或屬性。 xml web服務的服務描述使用xml,特別是在WSDL中。

我希望這可以幫助別人解決此問題...

相關問題