2011-10-05 8 views
0

wcfが新しく、クライアントから提供されたwsdlからWebサービスを作成しようとしています。私はwsdlを提供するwsdlと一致するようにwcf生成されたwsdlエントリを変更するのに問題があります。私はこれを見つけました:WSDL-first approach: How to specify different names for wsdl:port and wsdl:binding? 私は持っている問題を正確に記述していますが、そこで提供される解決策は.NET 4.0でVisual Studio 2010で動作しません。ここでwcf - wsdlポートタイプとバインディングを変更する

は、Web configです:

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
     <compilation debug="true" targetFramework="4.0"> 
     </compilation> 
     <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/></system.web> 
    <system.serviceModel> 

    <extensions> 
      <behaviorExtensions> 
       <add name="portName" type="CustomWsdlExtension.PortNameWsdlBehaviorExtension, CustomWsdlExtension, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> 
      </behaviorExtensions> 
     </extensions> 

    <services> 
     <service name="CustomWsdlExtension.Service" behaviorConfiguration="MyBehavior"> 
     <endpoint address="" binding="basicHttpBinding" contract="CustomWsdlExtension.IService" behaviorConfiguration="customPortName"/> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
    </services> 

    <behaviors> 
      <serviceBehaviors> 
       <behavior name="MyBehavior"> 
        <serviceMetadata httpGetEnabled="true"/> 
        <serviceDebug includeExceptionDetailInFaults="false"/> 
       </behavior> 
      </serviceBehaviors> 

     <endpointBehaviors> 
       <behavior name="customPortName"> 
        <portName name="myCustomName"/> 
       </behavior> 
      </endpointBehaviors> 
     </behaviors> 


     <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/> 
    </system.serviceModel> 
    <system.webServer> 
     <modules runAllManagedModulesForAllRequests="true"> 
     </modules> 
    </system.webServer> 
</configuration> 

とカスタムクラス:

  using System; 
       using System.Configuration; 
       using System.ServiceModel.Configuration; 
       using System.ServiceModel.Description; 

       namespace CustomWsdlExtension 
      { 
       public class PortNameWsdlBehavior : IWsdlExportExtension, IEndpointBehavior 
       { 
        public string Name { get; set; } 

        public void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context) 
        { 
        } 

        public void ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context) 
        { 
         if (!string.IsNullOrEmpty(Name)) 
         { 
          context.WsdlPort.Name = Name; 
         } 
        } 

        public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters) 
        { 
        } 

        public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime) 
        { 
        } 

        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher) 
        { 
        } 

        public void Validate(ServiceEndpoint endpoint) 
        { 
        } 
       } 

       public class PortNameWsdlBehaviorExtension : BehaviorExtensionElement 
       { 
        [ConfigurationProperty("name")] 
        public string Name 
        { 
         get 
         { 
          object value = this["name"]; 
          return value != null ? value.ToString() : string.Empty; 
         } 
         set { this["name"] = value; } 
        } 

        public override Type BehaviorType 
        { 
         get { return typeof(PortNameWsdlBehavior); } 
        } 

        protected override object CreateBehavior() 
        { 
         return new PortNameWsdlBehavior { Name = Name }; 
        } 
       } 
      }  

それは(私は要素の行動が「無効な子要素を持っていると言って警告Web構成を持って[OK]をコンパイルします'portName'期待される要素のリスト: 'clientVia、callbackDebug、callbackTimeouts、clear、clientCredentials、transactedBatching、dataContractSerializer、dispatcherSynchronization、remove、synchronousReceive、enableWebScript、webHttp、endpointDiscovery、soapProcessing'たVSのバグに関連すると思わ)

生成されたWSDLは、まだWSDLを示しています。ポート名=「BasicHttpBinding_IService1」結合=「TNS:BasicHttpBinding_IService1」>」ではなく修正ポート名以上。

ここでテストプロジェクト全体を見つけることができます:http://dl.dropbox.com/u/13875536/CustomWsdlExtension.zip ありがとうございます。

答えて

0

web.configにサービスと契約が反映されていないため、設定がまったく使用されないため、動作しません。

この部分は間違っている:

<services> 
    <service name="CustomWsdlExtension.Service" ... > 
    <endpoint contract="CustomWsdlExtension.IService" ... /> 
    ... 
    </service> 
</services> 

それは、フルサービス・クラスの名前とサービス契約を使用する必要があります。リンクされた回答から設定をコピーしただけでは不十分です。構成は使用するクラスに合っている必要があります。

<services> 
    <service name="CustomWsdlExtension.Service1" ... > 
    <endpoint contract="CustomWsdlExtension.IService1" ... /> 
    ... 
    </service> 
</services> 

また、以前の回答ではバインディング名を変更する方法が示されていません。そのための特別なコーディングはありません。構成内のEndpoint要素は、その目的のためにbindingName属性とbindingNamespace属性を持ちます。

+1

エラーが発生しました。素晴らしい仕事をした。しかし、bindingName属性を変更すると、バインディングの最初の部分だけが変更され、契約名は選択された名前に連結されます。 wsdlは ''ではなく、 'を表示します。何か案は?再度、感謝します。 – hopsoid

関連する問題