Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6644893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:13:13+00:00 2026-05-26T00:13:13+00:00

I am new to wcf and trying to create a webservice from a client

  • 0

I am new to wcf and trying to create a webservice from a client provided wsdl; I’m having trouble changing some wcf generated wsdl entries to match the provided wsdl. I found this: WSDL-first approach: How to specify different names for wsdl:port and wsdl:binding?
which exactly describes the issue i’m having but the solution provided there is not working in Visual Studio 2010 with .NET 4.0.

Here is the 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>

And the custom class:

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

It compiles ok (I have a warning web config saying The element ‘behavior’ has invalid child element ‘portName’. List of possible elements expected: ‘clientVia, callbackDebug, callbackTimeouts, clear, clientCredentials, transactedBatching, dataContractSerializer, dispatcherSynchronization, remove, synchronousReceive, enableWebScript, webHttp, endpointDiscovery, soapProcessing’ which seems to be related to a bug in VS)

The generated wsdl still shows wsdl:port name=”BasicHttpBinding_IService1″ binding=”tns:BasicHttpBinding_IService1″>’ rather than the modified port name.

You can find the whole test project here: http://dl.dropbox.com/u/13875536/CustomWsdlExtension.zip
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:13:14+00:00Added an answer on May 26, 2026 at 12:13 am

    It doesn’t work because your web.config doesn’t reflect your service and contract so the configuration is not used at all.

    This part is wrong:

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

    It must use full name of your service class and service contract. You just copied configuration from linked answer – it is not enough. Configuration must fit your classes to be used:

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

    Also the previous answer doesn’t show how to change the binding name. There is no special coding for that. Endpoint element in configuration has bindingName and bindingNamespace attributes for that purpose.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a WCF client that operates with an http rest
I am having a little trouble understanding ServiceKnownType in WCF. Taken from this blog
I am new to WCF. I was able to successfully create a client for
Im totally new to WCF. Trying to create a Silverlight application with WCF services.
I am new to WCF, trying to create a .net WCF service app. i
I'm trying to call a php webservice using WCF. I googled some public php
I'm new at WCF and i'm trying to create a service, it needs to
I was new to WCF, i was trying to build a sample application using
I am trying to create a common service library shared between a WCF web
I am trying to copy file(s) using webrequest inside WCF. I need some suggestions.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.