2011-01-18 6 views
3

wsdlファイルから「tempuri」参照を削除しようとしています。私は考えることができる既存のアドバイスにすべて従ってきました。実装クラスへIISでのWCF4ホスティング、WSDL:bindingNamespaceは決して読み取られません。

[ServiceBehavior(Namespace="mynamespace")] 

属性を追加し、契約インターフェイスに

[ServiceContract(Namespace="mynamespace")] 

を追加して、一致するように、web.configファイル内のエンドポイントの「bindingNamespace」属性を変更します。しかし(IISで)ロードされると、バインディングネームスペースは決して変更されません。常にテンポラリです。

誰もこの問題を修正する上で他の考えがありますか?以下は、Web設定のサンプルです... bindingnamespaceは、私が何をするにせよ、決してmynamespaceに更新されていません、常にtempuri.orgです。ホストファクトリを介してエンドポイントをロードした後、ホスト記述のバインディングを繰り返して更新すると、変更されますが、それはハックのようです。

サービスの場合:http://mydomain.com/MyService.svc次は、エンドポイントの設定を表していますが、これはIISでも使用されますか?依然としてWSDLでtempuri.org

<wsdl:import namespace="http://tempuri.org/" location="http://mydomain.org/MyService.svc?wsdl=wsdl0" /> 

........

<wsdl:service name="Directory"> 
    <wsdl:port name="BasicHttpBinding_IDirectoryServices" 
    binding="i0:BasicHttpBinding_IDirectoryServices"> 
     <soap:address location="http://mydomain.org/MyService.svc" /> 
    </wsdl:port> 
    </wsdl:service> 

を参照して生成されたWSDLファイルの

<services> 
    <service name="ServiceImplementationClassReference,MyAssembly" > 
    <endpoint name="" 
       address="MyService.svc" 
       binding="basicHttpBinding" 
       bindingNamespace="mynamespace" 
       bindingConfiguration="" 
       contract="IMyContract" /> 

    <endpoint name="mexHttpBinding" 
       address="mex" 
       binding="mexHttpBinding" 
       contract="IMetadataExchange" />   
    </service> 
</services> 

のrelavent片:定義ノードのXML名前空間i0(前述のサービスが参照する)もtempuri.orgに設定されているため、import文が必要です。 BasicHttpBindingまたはwsHttpBindingを使用すると、一時変数の使用に変更はありません。実際、web.configファイルのバインディングをwsHttpBindingに設定すると、上記の出力が得られ、BasicHttpBinding_IdirectoryServicesを参照します。

ありがとうございます!

+0

Ladislav、はいこれは.NET 4.0です。私はwsdlファイルの関連部分を追加しました。うまくいけば、これは役に立ちます。全体が正しくポストするために混乱するまでです。私はそれが役に立つと思うかもしれない誰にでも完全なものを送ることを嬉しく思っています。ありがとう!!私はあなたの援助に感謝します。 – Kevin

答えて

9

は既知の問題のように思える:https://connect.microsoft.com/wcf/feedback/details/583163/endpoint-bindingnamespace?wa=wsignin1.0

ここに私のweb.configのチョップです。私はあなたがする必要があるかもしれないものでYMMVので、HTTPSへの私の使用を制限していますのでご注意ください:

/// <summary> 
/// Attribute which will add a binding namespace to every endpoint it's used in. 
/// </summary> 
[AttributeUsage(AttributeTargets.Class)] 
public sealed class BindingNamespaceBehaviorAttribute : Attribute, IServiceBehavior 
{ 
    /// <summary> 
    /// The binding namespace; 
    /// </summary> 
    private readonly string bindingNamespace; 

    /// <summary> 
    /// Initializes a new instance of the <see cref="BindingNamespaceBehaviorAttribute"/> class. 
    /// </summary> 
    /// <param name="bindingNamespace">The binding namespace.</param> 
    public BindingNamespaceBehaviorAttribute(string bindingNamespace) 
    { 
     this.bindingNamespace = bindingNamespace; 
    } 

    /// <summary> 
    /// Gets the binding namespace. 
    /// </summary> 
    /// <value>The binding namespace.</value> 
    public string BindingNamespace 
    { 
     get 
     { 
      return this.bindingNamespace; 
     } 
    } 

    /// <summary> 
    /// Provides the ability to pass custom data to binding elements to support the contract implementation. 
    /// </summary> 
    /// <param name="serviceDescription">The service description of the service.</param> 
    /// <param name="serviceHostBase">The host of the service.</param> 
    /// <param name="endpoints">The service endpoints.</param> 
    /// <param name="bindingParameters">Custom objects to which binding elements have access.</param> 
    public void AddBindingParameters(
     ServiceDescription serviceDescription, 
     ServiceHostBase serviceHostBase, 
     Collection<ServiceEndpoint> endpoints, 
     BindingParameterCollection bindingParameters) 
    { 
    } 

    /// <summary> 
    /// Provides the ability to change run-time property values or insert custom extension objects such as error 
    /// handlers, message or parameter interceptors, security extensions, and other custom extension objects. 
    /// </summary> 
    /// <param name="serviceDescription">The service description.</param> 
    /// <param name="serviceHostBase">The host that is currently being built.</param> 
    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) 
    { 
    } 

    /// <summary> 
    /// Provides the ability to inspect the service host and the service description to confirm that the service 
    /// can run successfully. 
    /// </summary> 
    /// <param name="serviceDescription">The service description.</param> 
    /// <param name="serviceHostBase">The service host that is currently being constructed.</param> 
    public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) 
    { 
     if (serviceHostBase == null) 
     { 
      throw new ArgumentNullException("serviceHostBase"); 
     } 

     foreach (var endpoint in serviceHostBase.Description.Endpoints) 
     { 
      endpoint.Binding.Namespace = this.bindingNamespace; 
     } 
    } 
} 

<behaviors> 
     <endpointBehaviors> 
      <behavior name="Secure" /> 
     </endpointBehaviors> 
     <serviceBehaviors> 
      <behavior name="MetadataBehavior"> 
       <serviceMetadata httpsGetEnabled="true" /> 
       <serviceDebug includeExceptionDetailInFaults="true" /> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    <services> 
     <service name="Company.Services.Implementation.Service" behaviorConfiguration="MetadataBehavior"> 
      <endpoint address="" behaviorConfiguration="Secure" 
         binding="basicHttpBinding" bindingConfiguration="httpsBinding" bindingNamespace="http://services.company.com" 
         contract="Company.Services.Interfaces.IService" /> 
      <endpoint address="mex" behaviorConfiguration="Secure" 
         binding="mexHttpsBinding" bindingConfiguration="httpsBinding" bindingNamespace="http://services.company.com" 
         contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="httpsBinding"> 
       <security mode="Transport" /> 
      </binding> 
     </basicHttpBinding> 
     <mexHttpsBinding> 
      <binding name="httpsBinding" /> 
     </mexHttpsBinding> 
    </bindings> 

は、ここで(少し私が変更された)Raffaele Rialdiからコードごとのソリューションです

のように使用:

[ServiceBehavior(Namespace = "http://schemas.vevy.com/Printing")] 
[BindingNamespaceBehavior("http://schemas.vevy.com/Printing")] 
public class LabelsService : ILabelsService 
{ 
    // ... 
} 
+0

恐ろしいですが、少なくとも理由はあります!ありがとう、ジェシー、私はそこに見えるとは思わなかった、私はそれがアーキテクチャのバグであることを予期していなかった。 – Kevin

+0

ノードが全く読まれないように見える理由について私は興味がありますが。たとえば、私はmexエンドポイントへの参照を削除することができます。サービスは空の名前で定義されている限り、問題なくwsdlデータを処理します。名前付きインスタンスを名前付きインスタンスにするために空の名前を削除すると、メタデータは無効になりますが、この名前付きインスタンスをのbehaviorConfigruationとして適用すると何も行われません。 WCF 4の単純化された構成が、web.config =/ – Kevin

+0

内の項目によって上書きされていないかのように、これ以上の研究ではこれがデフォルトであると言われています。http://msdn.microsoft.com/en-us/library/ee358768 aspxこれをオーバーライドしてIISにweb.config設定のエンドポイントを使用させる方法は、IISの外部にカスタムホストを実装する唯一の方法ですか? – Kevin

関連する問題