Is basicHttpBinding really required when exposing a WCF service as a Web Service for .NET 2.0 Target Client?

强颜欢笑 提交于 2019-12-20 06:21:42

问题


I have a WCF service and am hosting it in a Windows Service.

I tried to add a reference for the service from a Windows Form client built on .NET 2.0. I could get the Web Reference by pointing to the httpGetUrl="http://localhost:8002/HBAccess/help/mex" but when I check the Reference.cs---It only contains a namespace with nothing in it.

Now I add the basicHttpBinding and repeat the same steps:

And now I can see the classes for the web service.

My senior colleague insist that setting the httpGetEnabled to true would be sufficient to export the WCF service via http and make a proper web reference.

Could anyone point me to what I am missing here?

<system.serviceModel>
<services>
  <service behaviorConfiguration="HBAcsNX.HBAccessBehavior" name="HBAcsNX.HBAccess">
        <!--<endpoint address="" binding="basicHttpBinding" contract="HBAcsNX.HBAccess" />-->
        <endpoint address="HBAccess" binding="netTcpBinding" contract="HBAcsNX.HBAccess" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
                <add baseAddress="net.tcp://localhost:18264/HBAccess/" />
                <add baseAddress="http://localhost:8002/HBAccess/" />
          </baseAddresses>
        </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
        <behavior name="HBAcsNX.HBAccessBehavior">
          <serviceDebug includeExceptionDetailInFaults="True" httpHelpPageUrl="http://localhost:8002/HBAccess/help" />
          <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8002/HBAccess/help/mex" />
        </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>

// Resulting Reference.cs (Empty proxy stub with only namespace)

#pragma warning disable 1591
namespace Form.ServiceClient {
}
#pragma warning restore 1591

回答1:


the problem is mexHttpBinding isn't actually exposing your service, its only exposing a defenition of your service, and since .net 2.0 doesn't understand nettcp you get an empty namespace, you need basicHttpBinding becuase that is your actually service endpoint.

if you look at the contracts you see that the contract for mexHttpBinding isn't even "HBAcsNX.HBAccess" but rather "IMetadataExchange".




回答2:


You have to specify a binding, and basicHttpBinding is the only one that interoperates with a .NET 2.0 client. .NET 2.0 ASMX clients only support XML over HTTP, and with no WS-* protocols.




回答3:


Your config doesn't quite line up.....

<service name="HBAcsNX.HBAccess"
         behaviorConfiguration="HBAcsNX.HBAccessBehavior" >
   <host>
       <baseAddresses>
            <add baseAddress="http://localhost:8002/HBAccess/" />
       </baseAddresses>
   </host>

   <endpoint address="mex" 
             binding="mexHttpBinding" contract="IMetadataExchange" />
</service>

If you take all this into account, you get http://localhost:8002/HBAccess/ from the base address, plus mex from the MEX endpoint --> http://localhost:8002/HBAccess/mex

But in your behavior configuration, you use a different address for MEX:

<behavior name="HBAcsNX.HBAccessBehavior">
    <serviceMetadata httpGetEnabled="true"
                     httpGetUrl="http://localhost:8002/HBAccess/help/mex" />
</behavior>

Here, you point at http://localhost:8002/HBAccess/help/mex - note the extra /help in there. Now which one is it really??

I would recommend tossing away the explicit httpGetUrl in the service behavior config - just use:

<behavior name="HBAcsNX.HBAccessBehavior">
    <serviceMetadata httpGetEnabled="true" />
</behavior>

and you should be able to get your MEX at http://localhost:8002/HBAccess/mex.

Marc



来源:https://stackoverflow.com/questions/1048287/is-basichttpbinding-really-required-when-exposing-a-wcf-service-as-a-web-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!