开发者

Cant access WCF self hosted service through IE

I have a self hosted WCF service.

I think the service is hosting ok but when I try and access the URL from IE nothing happens.

I have added some debugging and it looks like the service is hosting itself no problems.

Any help would be appreciated.

Kind Regards

Ash

Code to host service with debug

    Type serviceType = typeof(MessageHandlerServer);
    Uri serviceUri = new Uri("http://localhost:8080/");
    ServiceHost host = new ServiceHost(serviceType, serviceUri);
    host.Open();


    #region Output dispatchers listening
    foreach (Uri uri in host.BaseAddresses)
    {
         Console.WriteLine("\t{0}", uri.ToString());
    }
Console.WriteLine();
Console.WriteLine("Number of dispatchers listening : {0}", host.ChannelDispatchers.Count);
foreach (System.ServiceModel.Dispatcher.ChannelDispatcher dispatcher in host.ChannelDispatchers)
{
      Console.WriteLine("\t{0}, {1}", dispatcher.Listener.Uri.ToString(), dispatcher.BindingName);
}
Console.WriteLine();
Console.WriteLine("Press <ENTER> to terminate Host");
Console.ReadLine();
#endregion

Output is

Number of dispatchers listening : 2
http://localhost:8080/, http://tempuri.org/:WSDualHttpBinding
http://localhost:8080/, ServiceMetadataBehaviorHttpGetBinding

Press <ENTER> to terminate Host

Heres the service config, ignore the module downloader bit (unless you think thats causing the problem) its not relevant for now.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <system.diagnostics>
      <sources>
         <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
            <listeners>
               <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                  <filter type="" />
               </add>
               <add name="ServiceModelMessageLoggingListener">
                  <filter type="" />
               </add>
            </listeners>
         </source>
         <source name="System.ServiceModel" switchValue="Warning, ActivityTracing"
            propagateActivity="true">
            <listeners>
               <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                  <filter type="" />
               </add>
               <add name="ServiceModelTraceListener">
                  <filter type="" />
               </add>
            </listeners>
         </source>
      </sources>
      <sharedListeners>
         <add initializeData="C:\Users\Ash\Documents\Visual Studio 2010\Projects\FrameworkPrototype\Driver\App_messages.svclog"
            type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
            <filter type="" />
         </add>
         <add initializeData="C:\Users\Ash\Documents\Visual Studio 2010\Projects\FrameworkPrototype\Driver\App_tracelog.svclog"
            type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
            <filter type="" />
         </add>
      </sharedListeners>
   </system.diagnostics>
   <system.serviceModel>
    <diagnostics>
     <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
    </diagnostics>
    <bindings>
      <wsDualHttpBinding>
        <binding name="WSDualHttpBinding_IMessageHandlerServer" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
            maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
            messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00开发者_JAVA百科" />
          <security mode="Message">
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsDualHttpBinding>
      <basicHttpBinding>
        <binding name="HttpStreaming" maxReceivedMessageSize="67108864"
                 transferMode="Streamed"/>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="MessageHandlerServer" behaviorConfiguration="defaultProfile" >
        <endpoint address="http://localhost:8080" binding="wsDualHttpBinding"
          bindingConfiguration="WSDualHttpBinding_IMessageHandlerServer" contract="IMessageHandlerServer"  />
      </service>
      <service name="ModuleDownloader"  behaviorConfiguration="defaultProfile" >
        <endpoint address="http://localhost:8082" binding="basicHttpBinding"
          bindingConfiguration="HttpStreaming" contract="IModuleDownloader"  />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="defaultProfile">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceCredentials>
            <serviceCertificate findValue="MyServerCert" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My" />
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="UsernameValidator, MessageHandlerServer" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>


well unless you are getting IE to browse to the MEX, IE may not actually show much.

one of the easiest ways to test a WCF service is by way of MS's WCF Test Client (WcfTestClient.exe). I would try this before say using IE. This will not only test whether:

  • your service is contactable
  • your service is usable via standard WCF protocols (such as XML SOAP)
  • your service is NOT using any datatypes that do not adhere to SOAP

It also provides a nice little error dialog if something goes wrong, complete with details.

I notice your service is referring to X509. Is that setup correctly? Maybe try without? Sometimes it best to turn off security until you know for sure your service is contactable and invokable. If that works well maybe then turn on security.

An alternative to self-hosting is to host .svc WCF services in IIS. This takes alot of the guess work out. IIS's Manager GUI allows you to easily "browse" the .svc from the web applications Content folder, the output showing up rather nicely in IE (assuming your service is pushing out MEX)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜