2016-07-05 141 views
0

我在本地开发了一个WCF服务器并对其进行了测试,并且工作正常(返回字符串“Hello World”)。它托管在IISWCF服务返回.svc的页面内容(内容类型文本/ html例外)

但是,当我将它部署到托管在GoDaddy上的我的网站时,服务器将发送Service1.svc(描述内容)的页面内容而不是“Hello World!”,客户端并不期望也不处理。

客户端配置:

<?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> 

服务器配置:

<?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> 

客户端崩溃时调用服务的方法:上的Fiddler

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 

服务响应是www.XXXXX.com/Service.svc在浏览器中的确切内容:

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

您的支持是非常赞赏

+0

Godaddy中的IIS版本是什么。 –

+0

@ApurvaSaxena IIS 7.0 – user2209783

+0

@ApurvaSaxena请指教 – user2209783

回答

0

您需要在IIS或简单的办法可以使用注册MIME类型.SVC在IIS中的asp.net。请参阅链接msdn.microsoft.com/en-IN/library/k6h9cz8h(v=vs.100).aspx。

+0

据我所知,在IIS中注册asp.net将解决问题,如果它是本地的。我的本地版本的WCF正在运行并响应正常。但是,问题出在我的远程web服务上。 – user2209783

+0

请检查GoDaddy,可能他们没有做到这一点,让我知道如果不是这样的话...... –

+0

我最终改变了我的虚拟主机给另一个谁推荐的ASP.NET和我的Web服务工作新的托管环境。看来GoDaddy在WCF方面不是一个好选择。非常感谢您的努力 – user2209783