开发者

How to configure basicHttpBinding for WCF service

I have a WCF service that I'm trying to get to work with wcf, old soap and plain xml. The service is called TestService.svc and the configuration looks like this:

 <system.serviceModel>
  <behaviors>
   <serviceBehaviors>
    <behavior name="TestServiceBehavior">
     <serviceMetadata httpGetEnabled="true"/>
     <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
   </serviceBehaviors>
   <endpointBehaviors>
    <behavior name="poxBehavior">
     <webHttp/>
    &l开发者_StackOverflowt;/behavior>
   </endpointBehaviors>
  </behaviors>
  <services>
   <service behaviorConfiguration="TestServiceBehavior" name="TestService">
    <endpoint address="" binding="wsHttpBinding" contract="ITestService">
     <identity>
      <dns value="localhost"/>
     </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    <endpoint address="soap" binding="basicHttpBinding" contract="ITestService"/>
    <endpoint address="xml" binding="webHttpBinding"  behaviorConfiguration="poxBehavior" contract="ITestService"/>
   </service>
  </services>
 </system.serviceModel>

I got this code from this other question: REST / SOAP endpoints for a WCF service

Now, the XML webHttpBinding seems to work well, but the wsHttpBinding and basicHttpBinding does not work very well.

I can browser to the service using: http://localhost:8295/WCFTest/TestService.svc

I can also use that endpoint to add a service reference in an asp.net web site project and attempt to consume the service, but when I create the client:

TestService.TestServiceClient mytest = new TestService.TestServiceClient();

It says to specify an endpoint due to multiple endpoints. I guess due to having both wsHttp and basicHttp? How do I specify the endpoint here?

Next I try to consume the basicHttpBinding endpoint by adding a Web Reference (not service reference) to a .net 2.0 web site. At this point I'm not able to add the reference and receive an error 400.

So next I remove the wsHttp binding and am able to add the web reference and consume the service via a .net 2.0 client.

How do I configure it so that I can use wsHttpBinding for clients that can consume normal WCF services, basicHttpBinding for clients that can only consume older non-WCF SOAP requests and still have webHttpBinding available for clients that want to consume plain xml?


The person who posted this link (http://www.codemeit.com/wcf/wcf-restful-pox-json-and-soap-coexist.html) appears to be correct. But since this question remains unanswered, I'll elaborate a bit.

If you haven't tried it, I will mention first that nowhere in your configuration do you specify an actual address for the client service to connect to.

<service behaviorConfiguration="TestServiceBehavior" name="TestService">
  <endpoint address="" binding="wsHttpBinding" contract="ITestService">
    <identity>
      <dns value="localhost"/>
    </identity>
  </endpoint>
  <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  <endpoint address="soap" binding="basicHttpBinding" contract="ITestService"/>
  <endpoint address="xml" binding="webHttpBinding"  behaviorConfiguration="poxBehavior" contract="ITestService"/>
</service>

Your first endpoint has

<endpoint address="" binding="wsHttpBinding" contract="ITestService">

Based on documentation on MSDN (found here) and the link above, it appears that you are missing this in your service configuration

<host>
  <baseAddresses>
    <!-- note, choose an available port-->
    <add baseAddress="http://localhost:8295/WCFTest/TestService" />
  </baseAddresses>
</host>

Adding that would make your service configuration look like this

<service behaviorConfiguration="TestServiceBehavior" name="TestService">
  <host>
    <baseAddresses>
      <!-- note, choose an available port-->
      <add baseAddress="http://localhost:81/TestService" />
    </baseAddresses>
  </host>
  <endpoint address="" binding="wsHttpBinding" contract="ITestService">
    <identity>
      <dns value="localhost"/>
    </identity>
  </endpoint>
  <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  <endpoint address="soap" binding="basicHttpBinding" contract="ITestService"/>
  <endpoint address="xml" binding="webHttpBinding"  behaviorConfiguration="poxBehavior" contract="ITestService"/>
</service>

Adding that section will provide the address to use, while the specific endpoints will then use addresses relative to the base address provided.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜