WCF basic HTTP and NetTCP binding, exposing both via Mex
I'm having some difficulty getting my WCF service configured. My requirement is that it exposes a basicHttpBinding endpoint as well as a netTcpBinding endpoint. Some of my clients are .NET 2.0, and need to be able to generate a proxy via WSDL.exe.
It seems to work for the most part - but when I attempt to get the WSDL, it's not cooperating. In a browser, it gives me back some SOAP XML tags, but definitely not a full WSDL. WSDL.exe gives me a series of errors:
Error: There was an error processing 'http://1.2.3.4:9877/MyService/basicHttp?wsdl'.
- The document was understood, but it could not be processed.
- The WSDL document contains links that cou开发者_运维问答ld not be resolved.
- There was an error downloading 'http://localhost:9877/MyService/basicHttp?wsdl=wsdl0'.
- The underlying connection was closed: Unable to connect to the remote server.
Here's my host configuration. Does anything jump out as wrong here?
<system.serviceModel>
<services>
<service behaviorConfiguration="MyServiceBehavior" name="MyRunner">
<endpoint address="netTcp" binding="netTcpBinding" bindingConfiguration="" contract="IMyRunner">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="basicHttp" binding="basicHttpBinding" bindingConfiguration="" contract="IMyRunner">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9876/MyService/netTcp" />
<add baseAddress="http://localhost:9877/MyService/basicHttp" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
If you have two MEX endpoints, each needs a separate address - call one "mex", then call the other "mex2" or something:
<service behaviorConfiguration="MyServiceBehavior" name="MyRunner">
<endpoint address="netTcp" binding="netTcpBinding" bindingConfiguration="" contract="IMyRunner">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="basicHttp" binding="basicHttpBinding" bindingConfiguration="" contract="IMyRunner">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<endpoint address="mex2" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9876/MyService/netTcp" />
<add baseAddress="http://localhost:9877/MyService/basicHttp" />
</baseAddresses>
</host>
</service>
(OK so according to OP's comments, he's not hosting in IIS, so this is not relevant)
Also: are you hosting in IIS? In that case, your base addresses (at least the HTTP ones) are pointless - the server, virtual directory and location of the SVC file will dictate your service address:
http://YourServer/YourVirtualDirectory/SubDirectory/YourService.svc/basicHttp
for your "normal" servic endpoint, or
http://YourServer/YourVirtualDirectory/SubDirectory/YourService.svc/mex
for your HTTP based MEX endpoint.
Thanks for the tips guys. It turns out the problem was with the baseAddress values pointing to "localhost". In the WSDL that's generated, it still says "localhost", so WSDL.exe is apparently trying to reach localhost (my dev machine) instead of the server. I changed the "localhost" to the actual IP of the server that hosts the service, and WSDL.exe worked successfully, even in .NET 1.1. And I can still get the 4.0 version by using svcutil.exe.
精彩评论