Click here to Skip to main content
15,908,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
Hi sir,
     I created wcf service to perform addition operation, its working fine in basichttp binding, i cant able to view that service in wshttp binding. I tested the wcf service using wcftestclient utility, it is showing only basic httpbinding. I attached the service and web.config for your reference. Kindly check the code and tell me the solution for this problem.


Service.cs
****************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
public class Service : IService
{
    public int  Add(int a,int b)
    {
        return a + b;
    }
}


IService.cs
***************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
[ServiceContract]
public interface IService
{
    [OperationContract]
    int Add(int a, int b);
}


Web.config:
**************

<?xml version="1.0"?>
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0">
            <assemblies>
                <add assembly="System.Runtime.Remoting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies></compilation>
    </system.web>
    <system.serviceModel>
    <services>
      <service name="ArithmeticService.Service">

        <host>

          <baseAddresses>
            <add baseAddress="http://localhost:1234/arithmetics" />
          </baseAddresses>
        </host>
        <endpoint address="ws" binding="wsHttpBinding" contract="ArithmeticService.IService"/>
        <endpoint address="basic" binding="basicHttpBinding" contract="ArithmeticService.IService"/>

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
        <behaviors>
            <serviceBehaviors>
                <behavior>
                    <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                    <serviceMetadata httpGetEnabled="true"/>
                    <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                    <serviceDebug includeExceptionDetailInFaults="false"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
</configuration>
Posted

Prabu,

The first suspicion is that your wsHttpBinding endpoint is trying to use SSL (https://) by default. I've had to deal with this myself; it's maddening when everything "looks" correct, but the message never reaches your code, and all you get are cryptic (or zero) messages that are basically 500 errors.

Your basic setup appears to be correct--that is the recipe for putting multiple endpoints on a service. To overcome the individual requirements of each service (in this case, making the wsHttpEndpoint operation over a non-ssl connection), I recommend you make the following alterations:

First, add a bindings section under <system.serviceModel> like so:

XML
<bindings>
   <wsHttpBinding>
     <binding name="wsNonSSL">
       <security mode="None">
         <transport clientCredentialType="None" />
         <message clientCredentialType="None" />
       </security>
     </binding>
 </bindings>


In the bindings section, you can define multiple bindings and multiple settings for each binding. It can be confusing, so I put the basics: <security mode="None"/> says don't use SSL, and the transport and message credentials turn off the other ways that WSHttpBinding tries to verify security.

Now all you have to do is add a binding configuration reference to the appropriate endpoint, like so:
XML
<endpoint address="ws" binding="wsHttpBinding" contract="ArithmeticService.IService"  bindingConfiguration="wsNonSSL"/>


That tells your endpoint to use the configuration, which you have configured as a vanilla HTTP connection without any other requirements.

If you put it all together, your system.serviceModel tag should look like this (simplified):

XML
<system.serviceModel>
   <bindings>
      <wsHttpBinding>
        <binding name="wsNonSSL">
          <security mode="None">
            <transport clientCredentialType="None" />
            <message clientCredentialType="None" />
          </security>
        </binding>
    </bindings>
<services>
  <service name="ArithmeticService.Service">

    <host>

      <baseAddresses>
        <add baseAddress="http://localhost:1234/arithmetics" />
      </baseAddresses>
    </host>
    <endpoint address="ws" binding="wsHttpBinding" contract="ArithmeticService.IService" bindingConfiguration="wsNonSSL"/>
    <endpoint address="basic" binding="basicHttpBinding" contract="ArithmeticService.IService"/>

    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>
    <behaviors>
        <serviceBehaviors>
            <behavior>
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>


I hope this helps.
 
Share this answer
 
v4
Hello

The wcftestclient.exe test utility uses it's own config file and ignores yours. By default there is only a basicHttp binding in this config file.

What you need to do is edit the default file that wcftestclient provides and add in it the wsHttpBinding binding.

To edit the file look at your service in the WCF test client, there is a node "Config", right click and select "edit with svcconfigeditor"

It should not be long before you get it to work.

:)

Valery.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900