Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
376 views
in Technique[技术] by (71.8m points)

WCF Web.Config Question

I decided to migrate my legacy web service over to a WCF service called ServiceZ.svc. While moving things over went off without any issues and the application compiles AND I have other WCF TCP services running on my development machine, I cannot get this HTTP WCF service to load. I keep getting 404 errors no matter what I try - can somebody please review the included web.config section and help me figure out what is wrong? Thanks!

<system.serviceModel>  
    <services>  
      <service name="ServiceZ">  
        <endpoint address="http://localhost/Website/ServiceZ" binding="basicHttpBinding"
          name="MainHttpPoint" contract="IServiceZ" />  
        <endpoint address="mex" binding="mexHttpBinding" name="MexEP"  
          contract="IMetadataExchange" />  
        <host>  
          <baseAddresses>  
            <add baseAddress="http://localhost/Website/ServiceZ" />  
          </baseAddresses>  
        </host>  
      </service>  
    </services>  
    <bindings>  
      <basicHttpBinding>  
        <binding openTimeout="0:10:00" sendTimeout="00:10:00" />  
      </basicHttpBinding>  
    </bindings>  
    <behaviors>  
      <serviceBehaviors>  
        <behavior>  
          <serviceMetadata httpGetEnabled="true" />  
          <serviceDebug includeExceptionDetailInFaults="false" />  
        </behavior>  
      </serviceBehaviors>  
    </behaviors>  
  </system.serviceModel>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Depending how you want to configure this, you can take the following approach:

1) In the serviceBehaviors I tend to add the following within the behavior: (completely optional)

<useRequestHeadersForMetaAddress>
  <defaultPorts>
    <add scheme="http" port="__PORT__" />
  </defaultPorts>
</useRequestHeadersForMetaAddress>

This makes the service accessible with either a query using localhost, localserver1, www.webserver2.com, or fully.qualified.domain.com. (Makes for less headaches IMHO).

2) The endpoint addresses are relative to the baseAddress. That as to say you can use address="" for your default binding and address="mex" for your mexHttpBinding, given that baseAddress="http://localhost:__PORT__/Website/ServiceZ"

Most likely your WSDL problem is due to a mix of the two problems (basically, the service is saying all markup can be found on localhost (as specified by the endpoint address)--which is true when you run it locally, however when it's on a remote server this is no longer the case)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...