16

スタンドアロン アプリケーションを使用して WCF Web サービスを使用しようとしています。Internet Explorer を使用してこのサービスを表示することも、Visual Studio サービス参照で表示することもできます。

これは私が得ているエラーです

The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8).

これを変更して正しいコンテンツ タイプを使用するにはどうすればよいですか?

ここに私の設定ファイルがあります

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="G2WebServiceSoap11Binding" />
        </basicHttpBinding>
        <customBinding>
            <binding name="G2WebServiceSoap12Binding">
                <textMessageEncoding messageVersion="Soap12" />
                <httpTransport />
            </binding>
        </customBinding>
    </bindings>
    <client>
        <endpoint address="http://XXX.XX.XX.XX:XX/janus/services/G2WebService.G2WebServiceHttpSoap11Endpoint/"
            binding="basicHttpBinding" bindingConfiguration="G2WebServiceSoap11Binding"
            contract="G2ServiceReference.G2WebServicePortType"
            name="G2WebServiceHttpSoap11Endpoint" />
        <endpoint address="http://XXX.XX.XX.XX:XX/janus/services/G2WebService.G2WebServiceHttpSoap12Endpoint/"
            binding="customBinding" bindingConfiguration="G2WebServiceSoap12Binding"
            contract="G2ServiceReference.G2WebServicePortType"
            name="G2WebServiceHttpSoap12Endpoint" />
    </client>
</system.serviceModel>

ここにスタックがあります

{System.ServiceModel.ProtocolException: The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. 
The first 1024 bytes of the response were: '<Exception>org.apache.axis2.AxisFault: The endpoint reference (EPR) for the Operation not found is /janus/services/G2WebService and the WSA Action = null&#xd;
    at org.apache.axis2.engine.DispatchPhase.checkPostConditions(DispatchPhase.java:89)&#xd;
    at org.apache.axis2.engine.Phase.invoke(Phase.java:333)&#xd;
    at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:264)&#xd;
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:163)&#xd;
    at org.apache.axis2.transport.http.util.RESTUtil.invokeAxisEngine(RESTUtil.java:136)&#xd;
    at org.apache.axis2.transport.http.util.RESTUtil.processURLRequest(RESTUtil.java:130)&#xd;
    at org.apache.axis2.transport.http.AxisServlet$RestRequestProcessor.processURLRequest(AxisServlet.java:829)&#xd;
    at org.apache.axis2.transport.http.AxisServlet.doGet(AxisServlet.java:255)&#xd;
    at com.rm.janus.webservice.GroupCallServlet.doGet(GroupCallServlet.java:33)&#xd;
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)&#xd;
    at javax.servlet.http.HttpSer'. ---> System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   --- End of inner exception stack trace ---

Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at InetgrisG2TestApp.G2ServiceReference.G2WebServicePortType.getStudentData(getStudentDataRequest request)
   at InetgrisG2TestApp.G2ServiceReference.G2WebServicePortTypeClient.G2TestApp.G2ServiceReference.G2WebServicePortType.getStudentData(getStudentDataRequest request) in c:\Users\s\Documents\Visual Studio 2012\Projects\G2TestApp\InetgrisG2TestApp\Service References\G2ServiceReference\Reference.cs:line 2981
   at InetgrisG2TestApp.G2ServiceReference.G2WebServicePortTypeClient.getStudentData(ServiceRequest serviceReq) in c:\Users\s\Documents\Visual Studio 2012\Projects\G2TestApp\G2TestApp\Service References\G2ServiceReference\Reference.cs:line 2987
   at InetgrisG2TestApp.Program.Main(String[] args) in c:\Users\s\Documents\Visual Studio 2012\Projects\G2TestApp\G2TestApp\Program.cs:line 57}
4

8 に答える 8

18

WCF サービスが HTML を返している可能性があります。この場合、代わりに XML を返すようにサービス側でバインディングを設定する必要があります。ただし、これはほとんどありません。その場合お知らせください。詳細を編集します。

より可能性の高い理由は、サービスがエラーをスローし、HTML エラー ページを返すことです。詳細が必要な場合は、このブログ投稿をご覧ください。

tl;dr: エラー ページにはいくつかの可能な構成があります。IIS でホストしている場合は<httpErrors>、WCF サービスのweb.configファイルからセクションを削除する必要があります。そうでない場合は、サービス ホスティング シナリオの詳細を提供してください。それらに一致するように編集できます。

編集:

編集内容を確認すると、完全なエラーが返されていることがわかります。Apache は、どのサービスを呼び出したいかを判断できず、その理由でエラーをスローしています。正しいエンドポイントを取得すると、サービスは正常に機能します。間違った場所を指しています。残念ながら、入手可能な情報から正しい場所を判断することはできませんが、あなたの行動 (現時点ではnull!) または URL が間違っています。

于 2013-03-18T16:05:25.057 に答える
6

このエラーが発生したとき、解決策を見つけるのに何時間も費やしました。

私の問題は、ファイルを保存しようとしたときに、web.config で誤ってキー ストローク "G" を押してしまったことです。はぐれたキャラクターが外に座っているだけだったので、web.config は不適切にフォーマットされたデータを解釈する方法を知りませんでした。

お役に立てれば。

于 2014-10-29T15:52:32.707 に答える
1

WCF サービス プロジェクトでは、この問題は System.Web.Mvc.dll の異なるバージョンの参照が原因である可能性があります。または、他の DLL の異なるバージョンの問題である可能性があります。したがって、これはDLLの異なるバージョンの互換性の問題である可能性があります

私が使うとき

System.Web.Mvc.dll バージョン 5.2.2.0 ->エラーThe content type text/html;をスローします。応答メッセージの charset=utf-8

しかし、私が使用するとき

System.Web.Mvc.dll バージョン 4.0.0.0 以下-> 私のプロジェクトでは問題なく動作し、エラーは発生しません。

この異なるバージョンの DLL の問題の理由はわかりませんが、WCF プロジェクトと互換性のある DLL のバージョンを変更すると、問題なく動作します。

このエラーは、WCF プロジェクトに他のプロジェクトの参照を追加し、この参照プロジェクトに異なるバージョンの System.Web.Mvc DLL があるか、他の DLL である可能性がある場合にも生成されます。

于 2016-11-07T07:56:49.920 に答える
1

IIS の Url Rewrite 拡張機能を使用して、すべての HTTP 要求を HTTPS にリダイレクトします。http://... アドレスでトランスポート セキュリティを使用しないサービスを呼び出そうとすると、次のエラーが表示されます。

そのため、ブラウザ経由でサービスの http と https の両方のアドレスにアクセスできるかどうか、および 303 ステータス コードで自動転送されないかどうかを確認することをお勧めします。

于 2015-11-06T14:50:26.387 に答える
0

私の場合、それは単に web.config のエラーでした。

私が持っていた:

<endpoint address="http://localhost/WebService/WebOnlineService.asmx" 

次のようになっているはずです。

<endpoint address="http://localhost:10593/WebService/WebOnlineService.asmx"

アドレスにポート番号(:10593)がありませんでした。

于 2016-06-06T23:58:56.873 に答える