我在本地開發了一個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>
您的支持是非常讚賞
Godaddy中的IIS版本是什麼。 –
@ApurvaSaxena IIS 7.0 – user2209783
@ApurvaSaxena請指教 – user2209783