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