C# – What could be the reason for this WCF error

cvisual studiowcfwcf-binding

My WCF service[using basicHttpBinding] is hosted on IIS 6.Am able to access it using ?wsdl in the service url in IE browser .

I've a presenation layer in my winforms client and I added the reference of this service using ServiceReferences option in VS.Net which then generated a proxy.

When I call a method on this service, am getting this exception.What could I be missing here ?Thanks.

"Value cannot be null.Parameter name uri." at
System.ServiceModel.Description.ClientViaBehavior..ctor(Uri uri)
at System.ServiceModel.Configuration.ClientViaElement.CreateBehavior()
at
System.ServiceModel.Description.ConfigLoader.LoadBehaviors[T](ServiceModelExtensionCollectionElement1
behaviorElement, KeyedByTypeCollection
1 behaviors, Boolean
commonBehaviors)

at
System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint
serviceEndpoint, String configurationName)

at System.ServiceModel.ChannelFactory.ApplyConfiguration(String
configurationName) at
System.ServiceModel.ChannelFactory.InitializeEndpoint(String
configurationName, EndpointAddress address) at
System.ServiceModel.ChannelFactory1..ctor(String
endpointConfigurationName, EndpointAddress remoteAddress) at
System.ServiceModel.EndpointTrait
1.CreateSimplexFactory() at
System.ServiceModel.EndpointTrait1.CreateChannelFactory() at
System.ServiceModel.ClientBase
1.CreateChannelFactoryRef(EndpointTrait1
endpointTrait) at
System.ServiceModel.ClientBase
1.InitializeChannelFactoryRef() at
System.ServiceModel.ClientBase`1..ctor() at
TestingClient..ctor() in C:\Presentation\Service
References\ServiceReference1\Reference.cs:line 268

Here is my config xml for server and client:

*Server:

<system.serviceModel> 
    <bindings> 
      <basicHttpBinding> 
        <binding name="ProviderBinding" closeTimeout="00:01:00" openTimeout="00:01:00" 
               receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" 
               bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
               maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" 
               messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> 
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
          <security mode="Transport"> 
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> 
            <message clientCredentialType="UserName" algorithmSuite="Default" /> 
          </security> 
        </binding> 
      </basicHttpBinding> 
    </bindings> 
    <services> 
      <service name="PTSWeb.PriceTestingService" behaviorConfiguration="PTSWeb.Service1Behavior"> 
        <!-- Service Endpoints --> 
        <endpoint address="" binding="basicHttpBinding" contract="PTSWeb.IPriceTesting"> 
          <identity> 
            <dns value="localhost"/> 
          </identity> 
        </endpoint> 
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
      </service> 
    </services> 
    <behaviors> 
      <serviceBehaviors> 
        <behavior name="PTSWeb.Service1Behavior"> 
                <serviceMetadata httpGetEnabled="true"/> 
          <serviceDebug includeExceptionDetailInFaults="true"/> 
        </behavior> 
      </serviceBehaviors> 
    </behaviors> 
  </system.serviceModel>

*Client:

<system.serviceModel> 
    <client> 
      <endpoint address="http://localhost/PTSWeb/PTSWebService.svc" 
        behaviorConfiguration="PTSWeb.Service1Behavior" binding="basicHttpBinding" 
        bindingConfiguration="IPriceTestingBinding" contract="IPriceTesting" 
        name="IPriceTestingPort" /> 
      <endpoint address="https://qaserver/webservice" 
                binding="basicHttpBinding" bindingConfiguration="ProviderBinding" 
                contract="Provider" name="ProviderPort" />      
    </client> 
    <bindings> 
      <basicHttpBinding> 
        <binding name="IPriceTestingBinding" closeTimeout="00:01:00" 
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" 
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
          maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" 
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
          useDefaultWebProxy="true"> 
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
            maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
          <security mode="None" /> 
        </binding> 
        <binding name="ProviderBinding" closeTimeout="00:01:00" openTimeout="00:01:00" 
               receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" 
               bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
               maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" 
               messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> 
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
          <security mode="Transport"> 
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> 
            <message clientCredentialType="UserName" algorithmSuite="Default" /> 
          </security> 
        </binding> 
      </basicHttpBinding> 
    </bindings> 

    <behaviors> 
      <endpointBehaviors>      
        <behavior name="PTSWeb.Service1Behavior"> 
          <clientVia/> 
        </behavior> 
      </endpointBehaviors> 
  </behaviors> 
  </system.serviceModel>

Best Answer

In the client config behavior, you have a ClientVia element without any URI defined. Either remove this behavior or define the via Uri.

This quite well explain the goal and usage of the clientvia behavior : http://blogs.msdn.com/b/anilkumargupta/archive/2009/05/16/wcf-intermediate-service-between-client-and-server.aspx