简体   繁体   中英

WCF Service returns page content of .svc (The content type text/html exception)

I developed a WCF server locally and tested it and it works fine (returns string "Hello World"). It's hosted in IIS

But when I deploy it to my website hosted on GoDaddy, server sends the page content of Service1.svc (description content) instead of "Hello World!", which the client doesn't expect nor handle.

client config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IMessage2" />
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://mywebaddress/myservice/Service1.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMessage2"
            contract="ServiceReference2.IMessage" name="BasicHttpBinding_IMessage2" />
    </client>
</system.serviceModel>

Server Config:

<?xml version="1.0"?>
<configuration>

<appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
<httpModules>
  <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpModules>
</system.web>
<system.serviceModel>
<services>
  <service behaviorConfiguration="HelloServiceBehavior" name="HelloService.HelloService">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
      contract="HelloService.IMessage" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="HelloServiceBehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
    <add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>    
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
  <remove name="ApplicationInsightsWebTracking"/>
  <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
    preCondition="managedHandler"/>
</modules>
<!--
    To browse web app root directory during debugging, set the value below to true.
    Set to false before deployment to avoid disclosing web app folder information.
  -->
<directoryBrowse enabled="true"/>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>

</configuration>

client crashes when calling service method:

Unhandled Exception: System.ServiceModel.ProtocolException: The content type text/html; charset=utf-8 of the response message doesn't match the content type of the binding

Service response on Fiddler which is the exact content of www.XXXXX.com/Service.svc in browser:

 <HTML><HEAD><link rel="alternate" type="text/xml" href="http://XXXXXXX.net/myservice/Service1.svc?disco"/><STYLE type="text/css">#content{ FONT-SIZE: 0.7em; PADDING-BOTTOM: 2em; MARGIN-LEFT: 30px}BODY{MARGIN-TOP: 0px; MARGIN-LEFT: 0px; COLOR: #000000; FONT-FAMILY: Verdana; BACKGROUND-COLOR: white}P{MARGIN-TOP: 0px; MARGIN-BOTTOM: 12px; COLOR: #000000; FONT-FAMILY: Verdana}PRE{BORDER-RIGHT: #f0f0e0 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #f0f0e0 1px solid; MARGIN-TOP: -5px; PADDING-LEFT: 5px; FONT-SIZE: 1.2em; PADDING-BOTTOM: 5px; BORDER-LEFT: #f0f0e0 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: #f0f0e0 1px solid; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e5e5cc}.heading1{MARGIN-TOP: 0px; PADDING-LEFT: 15px; FONT-WEIGHT: normal; FONT-SIZE: 26px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 3px; MARGIN-LEFT: -30px; WIDTH: 100%; COLOR: #ffffff; PADDING-TOP: 10px; FONT-FAMILY: Tahoma; BACKGROUND-COLOR: #003366}.intro{MARGIN-LEFT: -15px}</STYLE><TITLE>HelloService Service</TITLE></HEAD><BODY><DIV id="content"><P class="heading1">HelloService Service</P><BR/><P class="intro">You have created a service.<P class='intro'>To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:</P> <BR/><PRE>svcutil.exe <A HREF="http://alqasm.net/myservice/Service1.svc?wsdl">http://alqasm.net/myservice/Service1.svc?wsdl</A></PRE><P>You can also access the service description as a single file:<BR/><PRE><A HREF="http://alqasm.net/myservice/Service1.svc?singleWsdl">http://alqasm.net/myservice/Service1.svc?singleWsdl</A></PRE></P></P><P class="intro"/>This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the Service. For example:<BR/><P class='intro'><B>C#</B></P><PRE><font color="blue">class </font><font color="teal">Test
</font>{
<font color="blue">    static void </font>Main()
    {
        <font color="teal">MessageClient</font> client = <font color="blue">new </font><font color="teal">MessageClient</font>();

<font color="green">        // Use the 'client' variable to call operations on the service.

</font><font color="green">        // Always close the client.
</font>        client.Close();
    }
}
</PRE><BR/><P class='intro'><B>Visual Basic</B></P><PRE><font color="blue">Class </font><font color="teal">Test
</font><font color="blue">    Shared Sub </font>Main()
<font color="blue">        Dim </font>client As <font color="teal">MessageClient</font> = <font color="blue">New </font><font color="teal">MessageClient</font>()
<font color="green">        ' Use the 'client' variable to call operations on the service.

</font><font color="green">        ' Always close the client.
</font>        client.Close()
<font color="blue">    End Sub
</font><font color="blue">End Class</font></PRE></DIV></BODY></HTML>

Your support is much appreciated

You need to add MIME type for .SVC in IIS or for easy fix use can register asp.net in IIS. See link msdn.microsoft.com/en-IN/library/k6h9cz8h(v=vs.100).aspx.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM