2011-10-05 2 views
0

wcf를 처음 사용하고 클라이언트에서 wsdl을 사용하여 webservice를 만들려고합니다. 제공된 wsdl과 일치하도록 일부 wcf 생성 wsdl 항목을 변경하는 데 문제가 있습니다. 나는 이것을 찾았습니다 : WSDL-first approach: How to specify different names for wsdl:port and wsdl:binding? 정확하게 문제를 설명하고 있지만 제공된 솔루션은 Visual Studio 2010 with .NET 4.0에서 작동하지 않습니다.wcf - wsdl 포트 유형 및 바인딩을 변경하십시오.

<?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 }; 
        } 
       } 
      }  

그것은 확인을 컴파일 (내가 가진 경고 웹 설정이 요소의 행동을 '말하는 잘못된 자식 요소가 'portName'예상 가능한 요소 목록 : 'clientVia, callbackDebug, callbackTimeouts, clear, clientCredentials, transactedBatching, dataContractSerializer, dispatcherSynchronization, remove, synchronousReceive, enableWebScript, webHttp, endpointDiscovery, soapProcessing' 포트 이름 = "BasicHttpBinding_IService1"바인딩 = "TNS : BasicHttpBinding_IService1을"> "보다 변형 포트 이름 같다는 생성 된 WSDL 여전히 WSDL을 도시 VS 버그)

관련된다.

여기에서 전체 테스트 프로젝트를 찾을 수 있습니다. 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 구성 요소에 해당 목적으로 bindingNamebindingNamespace 특성이 있습니다.

+1

새내기 오류! 잘 했어. 그러나 bindingName 속성을 변경하면 바인딩의 첫 번째 부분 만 변경되지만 여전히 계약 이름을 선택한 이름에 연결합니다. wsdl은 다음을 보여줍니다 : '대신 어떤 아이디어? 다시 한번 감사드립니다. – hopsoid

관련 문제