将WCF服务公开为.NET 2.0目标客户端的Web服务时,是否真的需要basicHttpBinding?

时间:2022-01-17 09:54:19

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

我有一个WCF服务,并在Windows服务中托管它。

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.

我尝试从基于.NET 2.0构建的Windows窗体客户端添加该服务的引用。我可以通过指向httpGetUrl =“http:// localhost:8002 / HBAccess / help / mex”来获取Web引用,但是当我检查Reference.cs时---它只包含一个没有任何内容的命名空间。

Now I add the basicHttpBinding and repeat the same steps:

现在我添加basicHttpBinding并重复相同的步骤:

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

现在我可以看到Web服务的类。

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.

我的高级同事坚持认为将httpGetEnabled设置为true足以通过http导出WCF服务并进行适当的Web引用。

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)

//结果Reference.cs(只有命名空间的空代理存根)

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

3 个解决方案

#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.

问题是mexHttpBinding实际上并没有暴露你的服务,它只暴露了你的服务的防御,并且由于.net 2.0不理解nettcp你得到一个空的命名空间,你需要basicHttpBinding,因为你的实际服务端点。

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

如果你查看合同,你会看到mexHttpBinding的合同甚至不是“HBAcsNX.HBAccess”而是“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.

您必须指定绑定,而basicHttpBinding是唯一可与.NET 2.0客户端互操作的绑定。 .NET 2.0 ASMX客户端仅支持基于HTTP的XML,并且不支持WS- *协议。

#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

如果考虑到所有这些,你可以从基地址获得http:// localhost:8002 / HBAccess /,从MEX端点获得mex - > http:// localhost:8002 / HBAccess / mex

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

但是在您的行为配置中,您为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??

在这里,你指向http:// localhost:8002 / HBAccess / help / mex - 注意那里的额外/帮助。现在哪一个真的?

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

我建议在服务行为配置中抛弃显式的httpGetUrl - 只需使用:

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

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

你应该能够在http:// localhost:8002 / HBAccess / mex上获得你的MEX。

Marc

#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.

问题是mexHttpBinding实际上并没有暴露你的服务,它只暴露了你的服务的防御,并且由于.net 2.0不理解nettcp你得到一个空的命名空间,你需要basicHttpBinding,因为你的实际服务端点。

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

如果你查看合同,你会看到mexHttpBinding的合同甚至不是“HBAcsNX.HBAccess”而是“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.

您必须指定绑定,而basicHttpBinding是唯一可与.NET 2.0客户端互操作的绑定。 .NET 2.0 ASMX客户端仅支持基于HTTP的XML,并且不支持WS- *协议。

#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

如果考虑到所有这些,你可以从基地址获得http:// localhost:8002 / HBAccess /,从MEX端点获得mex - > http:// localhost:8002 / HBAccess / mex

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

但是在您的行为配置中,您为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??

在这里,你指向http:// localhost:8002 / HBAccess / help / mex - 注意那里的额外/帮助。现在哪一个真的?

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

我建议在服务行为配置中抛弃显式的httpGetUrl - 只需使用:

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

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

你应该能够在http:// localhost:8002 / HBAccess / mex上获得你的MEX。

Marc