0

I have a WCF service that is hosted over HTTPS.

My client has to consume this service. While I create my cline tif I use this constructor

public MyServiceClient(string endpointConfigurationName, string remoteAddress) : 
    base(endpointConfigurationName, remoteAddress)
{
}

endpointConfigurationName is my .config binding Configuration and My client can talk to the service

But If I use this constructor

public MyServiceClient(Binding binding, EndpointAddress remoteAddress) : 
    base(binding, remoteAddress)
{
}

Use below to set my binding

 BasicHttpBinding binding = new BasicHttpBinding("BasicHttpBinding_IMyService");       

Then I get an exception when I client can talk to the service

{System.ServiceModel.FaultException: The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.

Server stack trace: 
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

Here is what my .config looks like.

<system.serviceModel>
    <bindings>
      <basicHttpBinding>

        <binding name="BasicHttpBinding_IMyService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="52428800" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>      

      </basicHttpBinding>

    </bindings>


    <client>
          <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService" contract="MyContract" name="BasicHttpBinding_IMyService"></endpoint>
    </client>
</system.serviceModel>

Can anyone please help me in understanding what is happening here?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
sunny
  • 69
  • 1
  • 11
  • 1
    It would help if you posted the `` section of your config. – Tim Feb 01 '16 at 21:43
  • Please add it to the question, not in the comments. – Tim Feb 01 '16 at 23:09
  • @Tim I am trying to Override the security mode in my client call in some cases, where the service is hosted in Http only, BasicHttpBinding myBinding = new BasicHttpBinding("BasicHttpBinding_IMyService"); if (Uri.UriSchemeHttp == uri.Scheme) { myBinding.Security.Mode = BasicHttpSecurityMode.None; } – sunny Feb 01 '16 at 23:33
  • What is the security mode set to at the service? The security mode between the service and the client must match. If you need an unsecure version, you'll need to expose a second endpoint for the contract with no security. – Tim Feb 02 '16 at 00:53
  • Hi @sunny, Is your wcf service is soap based or rest ? If it is a soap based service then you can try adding a service reference in your client project using service url then it would automatically adds the required binding configuration in your client config file and then you can use the service reference proxy to call your service methods in your client. – Bhupinder Singh Aug 31 '17 at 16:15

0 Answers0