Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WCF服务在服务器上引发错误(在本地工作正常)_Wcf_Wcf Binding - Fatal编程技术网

WCF服务在服务器上引发错误(在本地工作正常)

WCF服务在服务器上引发错误(在本地工作正常),wcf,wcf-binding,Wcf,Wcf Binding,我使用c#4.0和WCF 4.0创建了一个WCF服务,它在本地运行良好。使用WCf测试客户端和控制台应用程序作为客户端进行测试。但在部署该服务后,我尝试执行相同的操作,但它给出了以下错误。我不知道我做错了什么 内容类型text/html;响应消息的字符集=UTF-8与 绑定的内容类型(text/xml;charset=utf-8)。 如果使用自定义编码器,请确保正确实现IsContentTypeSupported方法。 响应的前1024个字节为: ' #内容{FONT-SIZE:0.7em;PA

我使用c#4.0和WCF 4.0创建了一个WCF服务,它在本地运行良好。使用WCf测试客户端和控制台应用程序作为客户端进行测试。但在部署该服务后,我尝试执行相同的操作,但它给出了以下错误。我不知道我做错了什么

内容类型text/html;响应消息的字符集=UTF-8与 绑定的内容类型(text/xml;charset=utf-8)。
如果使用自定义编码器,请确保正确实现IsContentTypeSupported方法。
响应的前1024个字节为:
' #内容{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:#f0e0 1px solid;FONT-FAMILY:Courier New;BACKGROUND-COLOR:e5ecc}。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:#ffffffff;PADDING-TOP:10px;FONT-FAMILY:Tahoma;BACKGROUND-COLOR:#003366}。简介{MARGIN-LEFT:-15px} 测试服务 服务器堆栈跟踪:
在System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest请求、HttpWebResponse响应、HttpChannelFactory
1工厂、WebException-responseException、ChannelBinding-ChannelBinding)
位于System.ServiceModel.Channels.HttpChannelFactory
1.HttpRequestChannel.HttpChannelRequest.WaitForReply(时间跨度超时)
位于System.ServiceModel.Channels.RequestChannel.Request(消息消息,TimeSpan超时)
位于System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,TimeSpan超时)
在System.ServiceModel.Channels.ServiceChannel.Call(字符串操作、布尔单向、ProxyOperationRuntime操作、对象[]输入、对象[]输出、时间跨度超时)
位于System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)
位于System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage消息)

正在调用服务::

public static void Main(string[] args)
{

    TestClient user = new TestClient();  
    string id = "rSmith";
    string u = user.GetUserName(id);
    user.Close();
    Console.WriteLine("The User you Requested is "+ u+" .");
}
服务网络配置

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="NameSoap" 
               closeTimeout="00:01:00" 
               openTimeout="00:01:00"
               receiveTimeout="00:10:00" 
               sendTimeout="00:01:00" 
               allowCookies="false"
               bypassProxyOnLocal="false" 
               hostNameComparisonMode="StrongWildcard"
               maxBufferSize="65536" 
               maxBufferPoolSize="524288" 
               maxReceivedMessageSize="65536"
               messageEncoding="Text" 
               textEncoding="utf-8" 
               transferMode="Buffered"
               useDefaultWebProxy="true">
        <readerQuotas maxDepth="32" 
                      maxStringContentLength="8192" 
                      maxArrayLength="16384"
                      maxBytesPerRead="4096" 
                      maxNameTableCharCount="16384" />
        <security mode="None">
          <transport clientCredentialType="None" 
                     proxyCredentialType="None"
                     realm="" />
          <message clientCredentialType="UserName" 
                   algorithmSuite="Default" />
        </security>
      </binding>
    </basicHttpBinding>
    <mexHttpBinding>
      <binding name="NewBinding1"/>
    </mexHttpBinding>
  </bindings>
  <!--<client/>-->
  <services>
    <service behaviorConfiguration="MyServiceTypebehaviors" 
             name="Test">
      <endpoint address="" 
                binding="basicHttpBinding" 
                bindingConfiguration="UserNameSoap" 
                bindingNamespace="https:/abc.com/Services/Test/"
                contract="Test.ITest" />
      <endpoint address="mex" 
                binding="mexHttpBinding" 
                bindingConfiguration="NewBinding1"
                contract="IMetadataExchange" />
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="MyServiceTypebehaviors">
        <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
        <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
        <serviceDebug includeExceptionDetailInFaults="true"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="false"
                             multipleSiteBindingsEnabled="true"/>
</system.serviceModel>

客户端配置文件

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_ITest" />
    </basicHttpBinding>
  </bindings>
  <client>            
    <endpoint address="http://abc.com/Services/Test/Test.svc"
              binding="basicHttpBinding" 
              bindingConfiguration="BasicHttpBinding_ITest"
              contract="DevService.ITest" 
              name="BasicHttpBinding_ITest" />         
  </client>
</system.serviceModel>

这里的问题是“响应消息与绑定的内容类型不匹配”

检查此链接,它解决了问题:


论坛解释实际问题,您可以从

中获得解决方案。这个问题有时会遇到一些棘手的问题,但对我来说,这始终是服务引用和服务之间的简单不匹配

更新服务引用时,它会更新该项目的web.config。
但是,如果web配置条目不在启动项目中,则它们对代码没有影响。因此,如果您的服务引用不在启动项目中,则在刷新服务引用时,您需要将相关的客户端条目从项目中复制到启动项目的web配置客户端部分。

您的合同不匹配在客户端和服务之间:

服务合同:“Test.ITest”


客户合同:“DevService.ITest”


客户端合约需要与服务合约匹配-在本例中,
Test.ITest
。即使
Test.ITest
DevService.ITest
是相同的代码,它们也会因为名称空间而被视为独立的


另外,您在绑定配置中指定的大约90%的设置是默认设置,您可以安全地忽略它们。

请发布您的代码(服务以及如何调用它)加上相关的配置文件。在将问题发布到stackoverflow之前,请搜索您的问题。以下是我发现的一些类似问题和可能的解决方案:您是否尝试更新您的服务引用并将其指向已部署的服务?我之前尝试过googlign和stackoverflow,并尝试了所有可能的解决方案,但没有获取问题解决方案我可以使用浏览器找到服务,也可以引用它,但在调用后,我得到了如上所述的响应。它应该返回一个Xml,并且我使用basicHttpBinding..因此我希望使用文本编码..在这里,当向项目添加引用时,im DevService在客户端定义..我们可以我们是否必须将名称空间与服务名称空间匹配???
<endpoint address="" 
          binding="basicHttpBinding" 
          bindingConfiguration="UserNameSoap" 
          bindingNamespace="https:/abc.com/Services/Test/"
          contract="Test.ITest" />
<endpoint address="http://abc.com/Services/Test/Test.svc"
          binding="basicHttpBinding" 
          bindingConfiguration="BasicHttpBinding_ITest"
          contract="DevService.ITest" 
          name="BasicHttpBinding_ITest" />